With VStack
& HStack
as a container, there is still a limitation of only 10 views that can be contained within. In order to bypass that limitation, you can use group to have more than 10 views.
An affordance for grouping view content.
Apple Documentation
In this tutorial, you’ll learn what it takes to build a Group in SwiftUI. You’ll learn:
- How to build a Group from scratch.
Prerequisites
To follow along this tutorial, you’ll need some basic knowledge in:
- A basic familiarity with Swift.
- At least Xcode 11
Group
You can always think of this as a term of grouping some component together. To better demonstrate this, you will create a VStack
that contains 10 views.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
VStack(spacing: 20) { Text("View 1") Text("View 2") Text("View 3") Text("View 4") Text("View 5") Text("View 6") Text("View 7") Text("View 8") Text("View 9") Text("View 10") } .padding() |

By adding 11th view, you will get an error “Type ‘CGFloat?’ does not conform to protocol ‘ExpressibleByIntegerLiteral“.
You can solve this by removing 10th View and replace it with Group.
1 2 3 4 5 6 |
Group { Text("View 10 (Inside group)") Text("View 11 (Inside group)") Text("View 12 (Inside group)") Text("View 13 (Inside group)") } |

Where to go From Here
If you feel like you are ready to take on more challenges, feel free to check out some other tutorials that we have created:
Be First to Comment