How to group views together in SwiftUI

Uplift iOS Interview

"Uplift iOS Interview" is a comprehensive guide to help aspiring iOS developers soar to new heights in their careers. This book is an indispensable tool for anyone looking to crack the iOS interview and impress their future employers with their technical prowess. With in-depth coverage of Swift, AutoLayout, SwiftUI, Multithreading, Memory management so on and so forth, this book is a treasure trove of knowledge for anyone looking to uplift their iOS development career.

There are several ways to group views together in SwiftUI. If you want to treat multiple views as a single entity and apply a common set of modifications or layouts, you can use the Group view in SwiftUI. It is important to note that, due to technical limitations, a parent view can only contain a maximum of 10 child views at once. Using a Group view can help you work around this limitation.

  1. You can use a Group view to wrap a collection of views together. The Group view doesn’t generate any visual output of its own, but it allows you to apply modifiers or layout to a group of views as a single entity. Note: If you attempt to add more than 10 views to a parent view in SwiftUI, you may encounter an error similar to ambiguous reference to member 'buildBlock()'. This is because the view building system in SwiftUI is only designed to support up to 10 views at a time. Attempting to add more than 10 views may cause errors and is not supported.

For example:

// Error ambiguous reference to member 'buildBlock()’
VStack {
    Text("Text 1")
    Text("Text 2")
    Text("Text 3")
    Text("Text 4")
    Text("Text 5")
    Text("Text 6")
    Text("Text 7")
    Text("Text 8")
    Text("Text 9")
    Text("Text 10")
    Text("Text 11")
    Text("Text 12")
}

// No error after grouping
VStack {
  Group {
    Text("Text 1")
    Text("Text 2")
    Text("Text 3")
    Text("Text 4")
    Text("Text 5")
    Text("Text 6")
    Text("Text 7")
  }
  Group {
    Text("Text 8")
    Text("Text 9")
    Text("Text 10")
    Text("Text 11")
    Text("Text 12")
  }
}
  1. You can use a VStack (vertical stack) or HStack (horizontal stack) to layout a collection of views in a horizontal or vertical line.
  1. You can use a ZStack (z-axis stack) to lay out views on top of each other.
  1. You can use a List to display a collection of views in a vertically scrolling list.
VStack {
    Text("Text 1")
    Text("Text 2")
}

HStack {
    Text("Text 1")
    Text("Text 2")
}

ZStack {
    Text("Text 1")
    Text("Text 2")
}

List {
    Text("Text 1")
    Text("Text 2")
}

Rev Up Your iOS Skills: Take a Dynamic Learning Journey
iOS Career Boost

iOS Career Boost is the ultimate learning journey to elevate your iOS development career through a dynamic blend of visual learning, handy cheat sheets, coding practice materials, and expertly curated tips and tricks


Get Ready to Shine: Mastering the iOS Interview


Enjoying the articles? Get the inside scoop by subscribing to my newsletter.

Get access to exclusive iOS development tips, tricks, and insights when you subscribe to my newsletter. You'll also receive links to new articles, app development ideas, and an interview preparation mini book. Your email address will only be used for the purpose of sending the newsletter and will not be shared with third parties or advertisers. Rest assured that we value your privacy and will not spam your inbox.


Connect with me on

Twitter and LinkedIn and don't hesitate to reach out with any questions about this post. Thank you for reading.

If you know someone who would benefit from reading this article, please share it with them.