ListState

@propertyWrapper
public struct ListState<Object> : DynamicProperty where Object : DynamicObject

A property wrapper type that can read ListPublisher changes.

Public

  • Creates an instance that observes ListPublisher changes and exposes a ListSnapshot value.

    @ListState
    var people: ListSnapshot<Person>
    
    init(listPublisher: ListPublisher<Person>) {
    
       self._people = .init(listPublisher)
    }
    
    var body: some View {
    
       List {
    
           ForEach(objectIn: self.people) { person in
    
               ProfileView(person)
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init(
        _ listPublisher: ListPublisher<Object>
    )

    Parameters

    listPublisher

    The ListPublisher that the ListState will observe changes for

  • Creates an instance that observes the specified FetchChainableBuilderType and exposes a ListSnapshot value.

    @ListState(
        From<Person>()
            .where(\.isMember == true)
            .orderBy(.ascending(\.lastName)),
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
       List {
    
           ForEach(objectIn: self.people) { person in
    
               ProfileView(person)
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init<B: FetchChainableBuilderType>(
        _ clauseChain: B,
        in dataStack: DataStack
    ) where B.ObjectType == Object

    Parameters

    clauseChain

    a FetchChainableBuilderType built from a chain of clauses

  • Creates an instance that observes the specified SectionMonitorBuilderType and exposes a ListSnapshot value.

    @ListState(
        From<Person>()
            .sectionBy(\.age)
            .where(\.isMember == true)
            .orderBy(.ascending(\.lastName)),
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
        List {
    
            ForEach(sectionIn: self.people) { section in
    
                Section(header: Text(section.sectionID)) {
    
                    ForEach(objectIn: section) { person in
    
                        ProfileView(person)
                    }
                }
            }
        }
        .animation(.default)
    }
    

    Declaration

    Swift

    public init<B: SectionMonitorBuilderType>(
        _ clauseChain: B,
        in dataStack: DataStack
    ) where B.ObjectType == Object

    Parameters

    clauseChain

    a SectionMonitorBuilderType built from a chain of clauses

  • Creates an instance that observes the specified From and FetchClauses and exposes a ListSnapshot value.

    @ListState(
        From<Person>(),
        Where<Person>(\.isMember == true),
        OrderBy<Person>(.ascending(\.lastName)),
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
       List {
    
           ForEach(objectIn: self.people) { person in
    
               ProfileView(person)
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init(
        _ from: From<Object>,
        _ fetchClauses: FetchClause...,
        in dataStack: DataStack
    )

    Parameters

    from

    a From clause indicating the entity type

    fetchClauses

    a series of FetchClause instances for fetching the object list. Accepts Where, OrderBy, and Tweak clauses.

  • Creates an instance that observes the specified From and FetchClauses and exposes a ListSnapshot value.

    @ListState(
        From<Person>(),
        [
            Where<Person>(\.isMember == true),
            OrderBy<Person>(.ascending(\.lastName))
        ],
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
       List {
    
           ForEach(objectIn: self.people) { person in
    
               ProfileView(person)
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init(
        _ from: From<Object>,
        _ fetchClauses: [FetchClause],
        in dataStack: DataStack
    )

    Parameters

    from

    a From clause indicating the entity type

    fetchClauses

    a series of FetchClause instances for fetching the object list. Accepts Where, OrderBy, and Tweak clauses.

  • Creates an instance that observes the specified From, SectionBy, and FetchClauses and exposes a sectioned ListSnapshot value.

    @ListState(
        From<Person>(),
        SectionBy(\.age),
        Where<Person>(\.isMember == true),
        OrderBy<Person>(.ascending(\.lastName)),
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
       List {
    
           ForEach(sectionIn: self.people) { section in
    
               Section(header: Text(section.sectionID)) {
    
                   ForEach(objectIn: section) { person in
    
                       ProfileView(person)
                   }
               }
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init(
        _ from: From<Object>,
        _ sectionBy: SectionBy<Object>,
        _ fetchClauses: FetchClause...,
        in dataStack: DataStack
    )

    Parameters

    from

    a From clause indicating the entity type

    sectionBy

    a SectionBy clause indicating the keyPath for the attribute to use when sorting the list into sections.

    fetchClauses

    a series of FetchClause instances for fetching the object list. Accepts Where, OrderBy, and Tweak clauses.

  • Creates an instance that observes the specified From, SectionBy, and FetchClauses and exposes a sectioned ListSnapshot value.

    @ListState(
        From<Person>(),
        SectionBy(\.age),
        [
            Where<Person>(\.isMember == true),
            OrderBy<Person>(.ascending(\.lastName))
        ],
        in: Globals.dataStack
    )
    var people: ListSnapshot<Person>
    
    var body: some View {
    
       List {
    
           ForEach(sectionIn: self.people) { section in
    
               Section(header: Text(section.sectionID)) {
    
                   ForEach(objectIn: section) { person in
    
                       ProfileView(person)
                   }
               }
           }
       }
       .animation(.default)
    }
    

    Declaration

    Swift

    public init(
        _ from: From<Object>,
        _ sectionBy: SectionBy<Object>,
        _ fetchClauses: [FetchClause],
        in dataStack: DataStack
    )

    Parameters

    from

    a From clause indicating the entity type

    sectionBy

    a SectionBy clause indicating the keyPath for the attribute to use when sorting the list into sections.

    fetchClauses

    a series of FetchClause instances for fetching the object list. Accepts Where, OrderBy, and Tweak clauses.

DynamicProperty

  • Declaration

    Swift

    public mutating func update()