Trying to print loop in the Xcode via vision os getting following error

Closure containing control flow statement cannot be used with result builder 'ViewBuilder'

below was the code

let feet = 9 let inch = 45

var body: some View {
    
    
    VStack{
        
        for number in 1...10 {
            print(number)
        }
    }

Replies

For loops are not a valid means of constructing a repeated sequence of views. You'll want to use the SwiftUI view named "ForEach".

https://developer.apple.com/documentation/swiftui/foreach

  • ohkk but It still showing the same error in the content view

Add a Comment