Wednesday, February 8, 2023
HomeiOS Developmentios - Might I do know why some model of code will...

ios – Might I do know why some model of code will trigger “Sort ‘()’ can not conform to ‘View'” in Swift UI?


I used to be questioning, why some model of code will trigger “Sort ‘()’ can not conform to ‘View'” in Swift UI?

The next code is OK

struct ContentView: View {
    var physique: some View {
        var a = 100
        
        VStack {
            Textual content("Hiya, world!")
        }
        .padding()
    }
}

The next code causes error

struct ContentView: View {
    var physique: some View {
        var a = 100
        a = 999
        
        VStack {
            Textual content("Hiya, world!")
        }
        .padding()
    }
}

The code will trigger

Sort '()' can not conform to 'View

Might I do know why it’s so? Is that this restriction imposed by Swift language, or imposed by SwiftUI framework?

My information is in UIKit, and I’m new to SwiftUI.

Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments