WIP: editable datasources

This commit is contained in:
John Estropia
2019-10-11 07:47:49 +09:00
parent d5114fc4bc
commit 81dfb8e3e5
21 changed files with 1253 additions and 479 deletions

View File

@@ -85,6 +85,35 @@ extension NSManagedObjectContext {
}
)
}
@nonobjc
internal func liveObject<D: DynamicObject>(id: NSManagedObjectID) -> LiveObject<D> {
let cache = self.liveObjectsCache(D.self)
return Internals.with {
if let liveObject = cache.object(forKey: id) {
return liveObject
}
let liveObject = LiveObject<D>(id: id, context: self)
cache.setObject(liveObject, forKey: id)
return liveObject
}
}
@nonobjc
private func liveObjectsCache<D: DynamicObject>(_ objectType: D.Type) -> NSMapTable<NSManagedObjectID, LiveObject<D>> {
let key = Internals.typeName(objectType)
if let cache = self.userInfo[key] {
return cache as! NSMapTable<NSManagedObjectID, LiveObject<D>>
}
let cache = NSMapTable<NSManagedObjectID, LiveObject<D>>.strongToWeakObjects()
self.userInfo[key] = cache
return cache
}
// MARK: Private