diff --git a/Sources/ForEach+SwiftUI.swift b/Sources/ForEach+SwiftUI.swift index 45dd41e..d91027a 100644 --- a/Sources/ForEach+SwiftUI.swift +++ b/Sources/ForEach+SwiftUI.swift @@ -35,6 +35,35 @@ import SwiftUI extension ForEach where Content: View { // MARK: Public + + /** + Creates an instance that creates views for each object in a collection of `ObjectSnapshot`s. The objects' `NSManagedObjectID` are used as the identifier + ``` + let people: [ObjectSnapshot] + + var body: some View { + + List { + + ForEach(self.people) { person in + + ProfileView(person) + } + } + .animation(.default) + } + ``` + + - parameter objectSnapshots: The collection of `ObjectSnapshot`s that the `ForEach` instance uses to create views dynamically + - parameter content: The view builder that receives an `ObjectPublisher` instance and creates views dynamically. + */ + public init( + _ objectSnapshots: Data, + @ViewBuilder content: @escaping (ObjectSnapshot) -> Content + ) where Data.Element == ObjectSnapshot, ID == O.ObjectID { + + self.init(objectSnapshots, id: \.cs_objectID, content: content) + } /** Creates an instance that creates views for each object in a `ListSnapshot`. diff --git a/Sources/ObjectSnapshot.swift b/Sources/ObjectSnapshot.swift index d80f8ae..3f39a18 100644 --- a/Sources/ObjectSnapshot.swift +++ b/Sources/ObjectSnapshot.swift @@ -127,6 +127,11 @@ public struct ObjectSnapshot: ObjectRepresentation, Hashable { self.values = values self.generation = .init() } + + internal var cs_objectID: O.ObjectID { + + return self.objectID() + } // MARK: FilePrivate