ListReader

public struct ListReader<Object, Content, Value> : View where Object : DynamicObject, Content : View

A container view that reads list changes in a ListPublisher

Internal

  • 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 the ListReader instance uses to create views dynamically

    content

    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 the ListReader instance uses to create views dynamically

    keyPath

    A KeyPath for a property in the ListSnapshot whose value will be sent to the views

    content

    The view builder that receives the value from the property KeyPath and creates views dynamically.

View

  • Declaration

    Swift

    public var body: some View { get }