<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Group",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5GroupV"
  },
  "title" : "Group"
}
-->

# Group

A type that collects multiple instances of a content type — like views,
scenes, or commands — into a single unit.

```
@frozen struct Group<Content>
```

## Overview

Use a group to collect multiple views into a single instance, without
affecting the layout of those views, like an [`HStack`](/documentation/SwiftUI/HStack),
[`VStack`](/documentation/SwiftUI/VStack), or [`Section`](/documentation/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 [`headline`](/documentation/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 [`ContentBuilder`](/documentation/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 [`onAppear(perform:)`](/documentation/SwiftUI/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 [`Text`](/documentation/SwiftUI/Text) instances,
meaning that the vertical stack’s content builder returns only two views —
the group, plus an additional [`Text`](/documentation/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 [`View`](/documentation/SwiftUI/View),
such as [`Scene`](/documentation/SwiftUI/Scene) and [`ToolbarContent`](/documentation/SwiftUI/ToolbarContent). The closure you
provide to the group initializer uses the corresponding builder type
([`SceneBuilder`](/documentation/SwiftUI/SceneBuilder), [`ToolbarContentBuilder`](/documentation/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.

## Topics

### Creating a group

[`init(content:)`](/documentation/SwiftUI/Group/init(content:))

Creates a group of content.

[`init(sections:transform:)`](/documentation/SwiftUI/Group/init(sections:transform:))

Constructs a group from the sections of the given view.

[`init(subviews:transform:)`](/documentation/SwiftUI/Group/init(subviews:transform:))

Constructs a group from the subviews of the given view.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)