ListReader
public struct ListReader<Object, Content, Value> : View where Object : DynamicObject, Content : View
A container view that reads list changes in a ListPublisher
-
Creates an instance that creates views for
ListPublisher
changes.let people: ListPublisher<Person> var body: some View { List { ListReader(self.people) { listSnapshot in ForEach(objectIn: listSnapshot) { person in ProfileView(person) } } } .animation(.default) }
Declaration
Swift
public init( _ listPublisher: ListPublisher<Object>, @ViewBuilder content: @escaping (ListSnapshot<Object>) -> Content ) where Value == ListSnapshot<Object>
Parameters
listPublisher
The
ListPublisher
that theListReader
instance uses to create views dynamicallycontent
The view builder that receives an
ListSnapshot
instance and creates views dynamically. -
Creates an instance that creates views for
ListPublisher
changes.let people: ListPublisher<Person> var body: some View { ListReader(self.people, keyPath: \.count) { count in Text("Number of members: \(count)") } }
Declaration
Swift
public init( _ listPublisher: ListPublisher<Object>, keyPath: KeyPath<ListSnapshot<Object>, Value>, @ViewBuilder content: @escaping (Value) -> Content )
Parameters
listPublisher
The
ListPublisher
that theListReader
instance uses to create views dynamicallykeyPath
A
KeyPath
for a property in theListSnapshot
whose value will be sent to the viewscontent
The view builder that receives the value from the property
KeyPath
and creates views dynamically.
-
Declaration
Swift
public var body: some View { get }