HomeiOS Developmentios - SwiftUI func navigationTitle the place title is Non-obligatory

ios – SwiftUI func navigationTitle the place title is Non-obligatory


Examined utilizing Xcode 14.3.1

Why every thing works positive with that extension

extension View {
    @ViewBuilder func setTitle<S>(_ title: Non-obligatory<S>) -> some View the place S : StringProtocol {
        if let title {
            self.navigationTitle(title)
        } else {
            self
        }
    }
}

however i get error from beneath circumstances:

Perform declares an opaque return sort ‘some View’, however the return statements in its physique shouldn’t have matching underlying sorts” the place:

extension View {
    func setTitle<S>(_ title: Non-obligatory<S>) -> some View the place S : StringProtocol {
        guard let title else { return self }
        return self.navigationTitle(title)
    }

Closure containing management circulate assertion can’t be used with outcome builder ‘ViewBuilder’ the place:

extension View {
    @ViewBuilder func setTitle<S>(_ title: Non-obligatory<S>) -> some View the place S : StringProtocol {
        guard let title else { self }
        self.navigationTitle(title)
    }
}

Perform opaque return sort was inferred as ‘_ConditionalContent<some View, Self>’, which defines the opaque sort when it comes to itself the place:

extension View {
    @ViewBuilder func navigationTitle<S>(_ title: Non-obligatory<S>) -> some View the place S : StringProtocol {
        if let title {
            self.navigationTitle(title)
        } else {
            self
        }
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments