Initializer
init(_:id:children:content:)
Creates an outline group from a root data element, the key path to its identifier, and a key path to its children.
Declaration
宣言
init<DataElement>(_ root: DataElement, id: KeyPath
<DataElement, ID>, children: KeyPath
<DataElement, Data?>, content: @escaping (DataElement) -> Leaf) where DataElement == Data.Element
Available when Data
conforms to RandomAccessCollection
, ID
conforms to Hashable
, Parent
conforms to View
, Parent
is Leaf
, and Subgroup
is DisclosureGroup<Parent, OutlineSubgroupChildren>
.
Parameters
パラメータ
root
The root of 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 a data element. 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 the data element as a leaf in the tree, like a regular file in a file system.
content
A view builder that produces a content view based on a data element.
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.
See Also
参照
Creating an Outline Group
init<DataElement>(Data, id: KeyPath<DataElement, ID>, children: KeyPath<DataElement, Data?>, content: (DataElement) -> Leaf)
Creates an outline group from a collection of root data elements, the key path to a data element’s identifier, and a key path to its children.
Available when Data
conforms to RandomAccessCollection
, ID
conforms to Hashable
, Parent
conforms to View
, Parent
is Leaf
, and Subgroup
is DisclosureGroup<Parent, OutlineSubgroupChildren>
.