added tool to convert existing NSManagedObjectModels to the new CoreStoreSchema

This commit is contained in:
John Estropia
2017-04-21 14:54:57 +09:00
parent 02a660e4a6
commit fe70b7a27d
16 changed files with 517 additions and 66 deletions

View File

@@ -78,29 +78,29 @@ public extension NSManagedObject {
}
@nonobjc @inline(__always)
public func getValue(forKvcKey kvcKey: KeyPath) -> Any? {
public func getValue(forKvcKey kvcKey: KeyPath) -> CoreDataNativeType? {
self.willAccessValue(forKey: kvcKey)
defer {
self.didAccessValue(forKey: kvcKey)
}
return self.primitiveValue(forKey: kvcKey)
return self.primitiveValue(forKey: kvcKey) as! CoreDataNativeType?
}
@nonobjc @inline(__always)
public func getValue<T>(forKvcKey kvcKey: KeyPath, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: KeyPath, didGetValue: (CoreDataNativeType?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: kvcKey)
defer {
self.didAccessValue(forKey: kvcKey)
}
return try didGetValue(self.primitiveValue(forKey: kvcKey))
return try didGetValue(self.primitiveValue(forKey: kvcKey) as! CoreDataNativeType?)
}
@nonobjc @inline(__always)
public func getValue<T>(forKvcKey kvcKey: KeyPath, willGetValue: () throws -> Void, didGetValue: (Any?) throws -> T) rethrows -> T {
public func getValue<T>(forKvcKey kvcKey: KeyPath, willGetValue: () throws -> Void, didGetValue: (CoreDataNativeType?) throws -> T) rethrows -> T {
self.willAccessValue(forKey: kvcKey)
defer {
@@ -108,12 +108,11 @@ public extension NSManagedObject {
self.didAccessValue(forKey: kvcKey)
}
try willGetValue()
return try didGetValue(self.primitiveValue(forKey: kvcKey))
return try didGetValue(self.primitiveValue(forKey: kvcKey) as! CoreDataNativeType?)
}
@nonobjc @inline(__always)
@discardableResult
public func setValue(_ value: Any?, forKvcKey KVCKey: KeyPath) -> Any? {
public func setValue(_ value: CoreDataNativeType?, forKvcKey KVCKey: KeyPath) {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -121,12 +120,10 @@ public extension NSManagedObject {
self.didChangeValue(forKey: KVCKey)
}
self.setPrimitiveValue(value, forKey: KVCKey)
return value
}
@nonobjc @inline(__always)
@discardableResult
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPath, willSetValue: (T) throws -> Any?) rethrows -> T {
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPath, willSetValue: (T) throws -> CoreDataNativeType?) rethrows {
self.willChangeValue(forKey: KVCKey)
defer {
@@ -134,20 +131,6 @@ public extension NSManagedObject {
self.didChangeValue(forKey: KVCKey)
}
self.setPrimitiveValue(try willSetValue(value), forKey: KVCKey)
return value
}
@nonobjc @inline(__always)
@discardableResult
public func setValue<T>(_ value: T, forKvcKey KVCKey: KeyPath, willSetValue: (T) throws -> Any?, didSetValue: (T) -> T = { $0 }) rethrows -> T {
self.willChangeValue(forKey: KVCKey)
defer {
self.didChangeValue(forKey: KVCKey)
}
self.setPrimitiveValue(try willSetValue(value), forKey: KVCKey)
return didSetValue(value)
}
/**