init(_:children:content:)
Creates an outline group from a binding to a collection of root data elements and a key path to its children.
Declaration
init<C, E>(_ data: Binding<C>, children: WritableKeyPath<E, C?>, @ViewBuilder content: @escaping (Binding<E>) -> Leaf) where Data == Binding<C>, ID == E.ID, C : MutableCollection, C : RandomAccessCollection, E : Identifiable, E == C.ElementParameters
- data:
A collection of tree-structured, identified data.
- children:
A key path to a property whose non-
nilvalue gives the children ofdata. A non-nilbut 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 isnil, then the outline group treatsdataas a leaf in the tree, like a regular file in a file system. - content:
A view 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.