Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VStack taking more then 10 elements in it. how error is not coming

I have code as below.

import SwiftUI

struct ContentView: View {
    var body: some View {
        
        VStack {
            Text("Line 0")
            Text("Line 1")
            Text("Line 2")
            Text("Line 3")
            Text("Line 4")
            Text("Line 5")
            Text("Line 6")
            Text("Line 7")
            Text("Line 8")
            Text("Line 9")
            
            Text("Line 10")
            Text("Line 11")
            Text("Line 12")
            Text("Line 13")
            Text("Line 14")
            Text("Line 15")
            Text("Line 16")
            Text("Line 17")
            Text("Line 18")
            Text("Line 19")
            
            Text("Line 20")
            Text("Line 21")
            Text("Line 22")
            Text("Line 23")
            Text("Line 24")
            Text("Line 25")
            Text("Line 26")
            Text("Line 27")
            Text("Line 28")
            Text("Line 29")
        
        }
    }
}

#Preview {
    ContentView()
}

What I know is there is limitation on the number of views it can accept as arguments. VStack can take max 10 views in it and hence Group is introduced.

However I am not getting any error and preview is working fine. Even app is running fine.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why error ambiguous reference to member 'buildBlock()’. is not coming?

>Solution :

ViewBuilder.buildBlock now takes a type parameter pack (introduced in Swift 5.9) instead of 11 separate overloads, each with a different number of type parameters.

static func buildBlock<each Content>(_ content: repeat each Content) 
    -> TupleView<(repeat each Content)> where repeat each Content : View

So there is no hardcoded limit on the number of views anymore. The only limit I suppose, would be how long it takes for Swift to type-check this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading