Outline Group
A structure that computes views and disclosure groups on demand from an underlying collection of tree-structured, identified data.
Platform Compatibility
Tags
SwiftUI Code
struct TreeItem: Identifiable {
let id = UUID()
let name: String
let children: [TreeItem]?
init(_ name: String, children: [TreeItem]? = nil) {
self.name = name
self.children = children
}
}
let data = [
TreeItem("Header", children: [
TreeItem("Foo", children: [
TreeItem("Foo 1"),
TreeItem("Foo 2")
]),
TreeItem("Bar", children: [
TreeItem("Bar 1"),
TreeItem("Bar 2")
])
])
]
var body: some View {
List {
OutlineGroup(data, children: \.children) { item in
Text(item.name)
}
}
}Found an issue or have a suggestion?
More List Components
View allDisclosure Group
A view that shows or hides another content view, based on the state of a disclosure control.
Section Index Label and Visibility
Sets the label that is used in a section index to point to this section, typically only a single character long. Changes the visibility of the list section index.
Explore Other Components
Browse allButton Styles
A type that applies standard interaction behavior and a custom appearance to all buttons within a view hierarchy
PalettePickerStyle
A picker style that presents the options as a row of compact elements. When used outside of menus, this style is rendered as a segmented picker. If that is the intended usage, consider segmented instead.
NavigationLinkPickerStyle
A picker style represented by a navigation link that presents the options by pushing a List-style picker view.