ListState
@propertyWrapper
public struct ListState<Object> : DynamicProperty where Object : DynamicObject
A property wrapper type that can read ListPublisher changes.
-
Creates an instance that observes
ListPublisherchanges and exposes aListSnapshotvalue.@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
listPublisherThe
ListPublisherthat theListStatewill observe changes for -
Creates an instance that observes the specified
FetchChainableBuilderTypeand exposes aListSnapshotvalue.@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 == ObjectParameters
clauseChaina
FetchChainableBuilderTypebuilt from a chain of clauses -
Creates an instance that observes the specified
SectionMonitorBuilderTypeand exposes aListSnapshotvalue.@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 == ObjectParameters
clauseChaina
SectionMonitorBuilderTypebuilt from a chain of clauses -
Creates an instance that observes the specified
FromandFetchClauses and exposes aListSnapshotvalue.@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
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for fetching the object list. AcceptsWhere,OrderBy, andTweakclauses. -
Creates an instance that observes the specified
FromandFetchClauses and exposes aListSnapshotvalue.@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
froma
Fromclause indicating the entity typefetchClausesa series of
FetchClauseinstances for fetching the object list. AcceptsWhere,OrderBy, andTweakclauses. -
Creates an instance that observes the specified
From,SectionBy, andFetchClauses and exposes a sectionedListSnapshotvalue.@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 ) -
Creates an instance that observes the specified
From,SectionBy, andFetchClauses and exposes a sectionedListSnapshotvalue.@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 )
-
Declaration
Swift
public mutating func update()
View on GitHub
ListState Structure Reference