Is there a limit to the number of files using VStacks

Hello,

I have a project with 6 simple SwiftUI files, each presenting simple views (Text, Image, Slider, DatePicker...).

When I create file number 7 (and following) I get an error on the entry to the VStack { (Unable to infer complex closure return type; add explicit type to disambiguate.)


I have tried cleaning the build folder. Closing the project, Xcode, and restarting them

If I create a new projet and paste the below in it compiles and executes rightly.


Any ideas ?


Cheers

Lars


import SwiftUI


struct Slider : View {

@State var celsius: Double = 0


var body: some View {

VStack {

Slider(value: $celsius, from: -100.00, through: 100.00, by: 1.0)

Text("\(celsius) Celsius is \(celsius * 9 / 5 + 32) Fahrenheit")

}

}

}


#if DEBUG

struct Slider_Previews : PreviewProvider {

static var previews: some View {

Slider()

}

}

#endif

Not sure if this is your issue, but I've been told that VStack's are limited to 10 items.

You're creating your own type named “Slider”, but SwiftUI already has a type named “Slider”. Your Slider type doesn't have an init compatible with the signature init(value: Binding<Double>, from: Double, through: Double, by: Double), so the attempt to create a Slider inside the VStack fails and generates the “Unable to infer complex closure return type” error.


I can make your code compile by explicitly creating the nested Slider using the SwiftUI module name:

struct Slider : View {
     @State var celsius: Double = 0
      var body: some View {
         VStack {
             SwiftUI.Slider(value: $celsius, from: -100.00, through: 100.00, by: 1.0)
             Text("\(celsius) Celsius is \(celsius * 9 / 5 + 32) Fahrenheit")
         }
     }
 }

Realistically, this is not a good solution. You should not make your own type named “Slider”. You should rename your type to something else like “TemperatureControl”.

You can embed more items in a VStack by using Groups.


struct ContentView : View {
    var body: some View {
        VStack {
            Group {
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
            }
            Group {
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
                Text("Hello World")
            }
        }
    }
}
Is there a limit to the number of files using VStacks
 
 
Q