DiffableDataSource.CollectionView implementation

This commit is contained in:
John Estropia
2019-10-16 14:01:25 +09:00
parent 7932625644
commit 64a0264354
14 changed files with 383 additions and 90 deletions

View File

@@ -69,40 +69,50 @@ public protocol ObjectRepresentation {
func asObjectMonitor(in dataStack: DataStack) -> ObjectMonitor<ObjectType>?
}
extension LiveObject {
public static func cs_object(in context: NSManagedObjectContext) -> LiveObject<O>? {
return nil
}
}
extension NSManagedObject: ObjectRepresentation {}
extension ObjectMonitor {
public static func cs_object(in context: NSManagedObjectContext) -> LiveObject<D>? {
return nil
}
}
extension NSManagedObject: ObjectRepresentation {
}
extension CoreStoreObject: ObjectRepresentation {
}
extension CoreStoreObject: ObjectRepresentation {}
extension DynamicObject where Self: ObjectRepresentation {
public static func cs_object(in context: NSManagedObjectContext) -> LiveObject<Self>? {
fatalError()
// MARK: ObjectRepresentation
public func objectID() -> Self.ObjectID {
return self.cs_id()
}
public func cs_rawObject(in context: NSManagedObjectContext) -> NSManagedObject? {
public func asLiveObject(in dataStack: DataStack) -> LiveObject<Self>? {
let context = dataStack.unsafeContext()
return .init(objectID: self.cs_id(), context: context)
}
public func asEditable(in transaction: BaseDataTransaction) -> Self? {
let context = transaction.unsafeContext()
if self.cs_toRaw().managedObjectContext == context {
return self
}
return context.fetchExisting(self.cs_id())
}
public func asSnapshot(in dataStack: DataStack) -> ObjectSnapshot<Self>? {
let context = dataStack.unsafeContext()
return .init(objectID: self.cs_id(), context: context)
}
public func asSnapshot(in transaction: BaseDataTransaction) -> ObjectSnapshot<Self>? {
let context = transaction.unsafeContext()
return .init(objectID: self.cs_id(), context: context)
}
public func asObjectMonitor(in dataStack: DataStack) -> ObjectMonitor<Self>? {
let context = dataStack.unsafeContext()
return .init(objectID: self.cs_id(), context: context)
}
}