SwiftUI has one very important limit, each view can’t have more than 10 subviews. It’s because of the way how SwiftUI was created.
There is a way to create more views than this limit. To do it you need to use the Group view. It doesn’t change anything in layout.
When you put more than 10 subviews in any other, for example Stacks, you won’t be able to run this code.
For example, it won’t work because there are 12 views:
var body: some View {
VStack {
Text(“Image one:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image two:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image three:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image four:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image five:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image six:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
}
}
To fix it, embed some part of view into Group.
var body: some View {
VStack {
Group {
Text(“Image one:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image two:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image three:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
}
Group {
Text(“Image four:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image five:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
Text(“Image six:”)
Image(“sydney”).resizable().frame(width: 100, height: 50)
}
}
}
Now, the code works.