One Logo Pool Ball
SwiftUICore · IOS API REFERENCE

Group

struct · iOS 13.0+ · SDK 27.1

@frozen struct Group<Content>

A type that collects multiple instances of a content type --- like views, scenes, or commands --- into a single unit. Use a group to collect multiple views into a single instance, without affecting the layout of those views, like an ``SwiftUI/HStack``, ``SwiftUI/VStack``, or ``SwiftUI/Section`` would. After creating a group, any modifier you apply to the group affects all of that group's members. For example, the following code applies the ``SwiftUI/Font/headline`` font to three views in a group. Group { Text("SwiftUI") Text("Combine") Text("Swift System") } .font(.headline) Because you create a group of views with a ``SwiftUI/ContentBuilder``, you can use the group's initializer to produce different kinds of views from a conditional, and then optionally apply modifiers to them. The following example uses a `Group` to add a navigation bar title, regardless of the type of view the conditional produces: Group { if isLoggedIn { WelcomeView() } else { LoginView() } } .navigationBarTitle("Start") The modifier applies to all members of the group --- and not to the group itself. For example, if you apply ``View/onAppear(perform:)`` to the above group, it applies to all of the views produced by the `if isLoggedIn` conditional, and it executes every time `isLoggedIn` changes. Because a group of views itself is a view, you can compose a group within other content builders, including nesting within other groups. This allows you to add large numbers of views to different content builder containers. The following example uses a `Group` to collect 10 ``SwiftUI/Text`` instances, meaning that the vertical stack's content builder returns only two views --- the group, plus an additional ``SwiftUI/Text``: var body: some View { VStack { Group { Text("1") Text("2") Text("3") Text("4") Text("5") Text("6") Text("7") Text("8") Text("9") Text("10") } Text("11") } } You can initialize groups with several types other than ``SwiftUI/View``, such as ``SwiftUI/Scene`` and ``SwiftUI/ToolbarContent``. The closure you provide to the group initializer uses the corresponding builder type (``SwiftUI/SceneBuilder``, ``SwiftUI/ToolbarContentBuilder``, and so on), and the capabilities of these builders vary between types. For example, you can use groups to return large numbers of scenes or toolbar content instances, but not to return different scenes or toolbar content based on conditionals.

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

3 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

Group.init(content:)

callback cannot propagate synchronous failure

Group.init(subviews:transform:)

callback cannot propagate synchronous failure

Group.init(sections:transform:)

callback cannot propagate synchronous failure

All SwiftUICore types →