mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-26 11:21:32 +01:00
added sugar syntax for ForEach that removes requirement for the "id:" argument
This commit is contained in:
@@ -35,6 +35,35 @@ import SwiftUI
|
|||||||
extension ForEach where Content: View {
|
extension ForEach where Content: View {
|
||||||
|
|
||||||
// MARK: Public
|
// 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<Person>]
|
||||||
|
|
||||||
|
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<O: DynamicObject>(
|
||||||
|
_ objectSnapshots: Data,
|
||||||
|
@ViewBuilder content: @escaping (ObjectSnapshot<O>) -> Content
|
||||||
|
) where Data.Element == ObjectSnapshot<O>, ID == O.ObjectID {
|
||||||
|
|
||||||
|
self.init(objectSnapshots, id: \.cs_objectID, content: content)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates an instance that creates views for each object in a `ListSnapshot`.
|
Creates an instance that creates views for each object in a `ListSnapshot`.
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ public struct ObjectSnapshot<O: DynamicObject>: ObjectRepresentation, Hashable {
|
|||||||
self.values = values
|
self.values = values
|
||||||
self.generation = .init()
|
self.generation = .init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal var cs_objectID: O.ObjectID {
|
||||||
|
|
||||||
|
return self.objectID()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: FilePrivate
|
// MARK: FilePrivate
|
||||||
|
|||||||
Reference in New Issue
Block a user