ForEach
extension ForEach where Content: View
-
Creates an instance that creates views for each object in a collection of
ObjectSnapshots. The objects’NSManagedObjectIDare used as the identifierlet people: [ObjectSnapshot<Person>] var body: some View { List { ForEach(self.people) { person in ProfileView(person) } } .animation(.default) }Declaration
Swift
public init<O: DynamicObject>( _ objectSnapshots: Data, @ViewBuilder content: @escaping (ObjectSnapshot<O>) -> Content ) where Data.Element == ObjectSnapshot<O>, ID == O.ObjectIDParameters
objectSnapshotsThe collection of
ObjectSnapshots that theForEachinstance uses to create views dynamicallycontentThe view builder that receives an
ObjectPublisherinstance and creates views dynamically. -
Creates an instance that creates views for each object in a
ListSnapshot.@ListState var people: ListSnapshot<Person> var body: some View { List { ForEach(objectIn: self.people) { person in ProfileView(person) } } .animation(.default) }Declaration
Swift
public init<O: DynamicObject>( objectIn listSnapshot: Data, @ViewBuilder content: @escaping (ObjectPublisher<O>) -> Content ) where Data == ListSnapshot<O>, ID == O.ObjectIDParameters
listSnapshotThe
ListSnapshotthat theForEachinstance uses to create views dynamicallycontentThe view builder that receives an
ObjectPublisherinstance and creates views dynamically. -
Creates an instance that creates views for each object in a collection of
ObjectPublishers.let people: [ObjectPublisher<Person>] var body: some View { List { ForEach(objectIn: self.people) { person in ProfileView(person) } } .animation(.default) }Declaration
Swift
public init<O: DynamicObject>( objectIn objectPublishers: Data, @ViewBuilder content: @escaping (ObjectPublisher<O>) -> Content ) where Data.Element == ObjectPublisher<O>, ID == O.ObjectIDParameters
objectPublishersThe collection of
ObjectPublishers that theForEachinstance uses to create views dynamicallycontentThe view builder that receives an
ObjectPublisherinstance and creates views dynamically. -
Creates an instance that creates views for
ListSnapshotsections.@ListState 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<O: DynamicObject>( sectionIn listSnapshot: ListSnapshot<O>, @ViewBuilder content: @escaping (ListSnapshot<O>.SectionInfo) -> Content ) where Data == [ListSnapshot<O>.SectionInfo], ID == ListSnapshot<O>.SectionIDParameters
listSnapshotThe
ListSnapshotthat theForEachinstance uses to create views dynamicallycontentThe view builder that receives a
ListSnapshot.SectionInfoinstance and creates views dynamically. -
Creates an instance that creates views for each object in a
ListSnapshot.SectionInfo.@ListState 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<O: DynamicObject>( objectIn sectionInfo: Data, @ViewBuilder content: @escaping (ObjectPublisher<O>) -> Content ) where Data == ListSnapshot<O>.SectionInfo, ID == O.ObjectIDParameters
sectionInfoThe
ListSnapshot.SectionInfothat theForEachinstance uses to create views dynamicallycontentThe view builder that receives an
ObjectPublisherinstance and creates views dynamically.
View on GitHub
ForEach Extension Reference