---
title: "init(sections:transform:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/group/init(sections:transform:)"
---

# init(sections:transform:)

Constructs a group from the sections of the given view.

## Declaration

```swift
init<Base, Result>(sections view: Base, @ContentBuilder transform: @escaping (SectionCollection) -> Result) where Content == GroupSectionsOfContent<Base, Result>, Base : View, Result : View
```

## Parameters

- `view`: The view to extract the sections of.

## Discussion

Discussion Sections are constructed lazily, on demand, so access only as much of this collection as is necessary to create the resulting content. struct SectionedStack<Content: View>: View {     var content: Content

init(@ContentBuilder content: () -> Content) {         self.content = content()     }

var body: some View {         VStack {             Group(sections: content) { sections in                 ForEach(sections) { section in                     SectionChrome {                         section.content                     } header: {                         section.header                     } footer: {                         section.footer                     }                 }             }         }     } } This can then be used by creating a SectionedStack with it’s content builder-based initializer. SectionedStack {     Section("Header A") {         Text("Hello")         Text("World")     } footer: {         Text("Footer A")     }     Section("Header B") {         Text("Foo")         Text("Bar")     } footer: {         Text("Footer B")     } } Any content of the given view which is not explicitly specified as a section is grouped with its sibling content to form implicit sections, meaning the minimum number of sections in a SectionCollection is one. For example in the following SectionedStack, there is one explicit section, and two implicit sections containing the content before, and after the explicit section: SectionedStack {     Text("First implicit section")     Section("Explicit section") {         Text("Content")     }     Text("Second implicit section") }

## See Also

### Creating a group

- [init(content:)](swiftui/group/init(content:).md)
- [init(subviews:transform:)](swiftui/group/init(subviews:transform:).md)
