<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/OutlineGroup/init(_:id:children:content:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI12OutlineGroupVA2A4ViewR0_q1_Rs0_AA010DisclosureD0Vyq0_AA0C16SubgroupChildrenVGRs2_rlE_2id8children7contentACyAA7BindingVyqd__Gq_q0_q0_AIGAO_s7KeyPathCyqd_0_q_Gs08WritablemN0Cyqd_0_qd__SgGq0_ANyqd_0_GctcAORszSMRd__SkRd__7ElementSTQyd__Rsd_0_r0_lufc::OverloadGroup"
  },
  "title" : "init(_:id:children:content:)"
}
-->

# init(_:id:children:content:)

Creates an outline group from a binding to a collection of root data
elements, the key path to a data element’s identifier, and a key path to
its children.

```
init<C, E>(_ data: Binding<C>, id: KeyPath<E, ID>, children: WritableKeyPath<E, C?>, @ContentBuilder content: @escaping (Binding<E>) -> Leaf) where Data == Binding<C>, C : MutableCollection, C : RandomAccessCollection, E == C.Element
```

## Parameters

`data`

A collection of tree-structured, identified data.

`id`

The key path to a data element’s identifier.

`children`

A key path to a property whose non-`nil` value gives the
children of `data`. A non-`nil` but empty value denotes an element
capable of having children that’s currently childless, such as an
empty directory in a file system. On the other hand, if the property
at the key path is `nil`, then the outline group treats `data` as a
leaf in the tree, like a regular file in a file system.

`content`

A content builder that produces a content view based on an
element in `data`.

## Discussion

This initializer creates an instance that uniquely identifies views
across updates based on the identity of the underlying data element.

All generated disclosure groups begin in the collapsed state.

Make sure that the identifier of a data element only changes if you
mean to replace that element with a new element, one with a new
identity. If the ID of an element changes, then the content view
generated from that element will lose any current state and animations.

---

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)