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

@@ -31,6 +31,78 @@ import Foundation
public protocol MigrationMappingProvider {
associatedtype SourceType: DynamicObject
associatedtype DestinationType: DynamicObject
associatedtype SourceSchema: DynamicSchema
associatedtype DestinationSchema: DynamicSchema
var sourceSchema: SourceSchema { get }
var destinationSchema: DestinationSchema { get }
init(source: SourceSchema, destination: DestinationSchema)
// func migrate(
// from oldObject: SourceType,
// to newObject: DestinationType,
// transaction: UnsafeDataTransaction
// )
//
// func forEachPropertyMapping(
// from oldObject: SourceType,
// to newObject: DestinationType,
// removed: (_ keyPath: KeyPath) -> Void,
// added: (_ keyPath: KeyPath) -> Void,
// transformed: (_ keyPath: KeyPath) -> Void,
// copied: (_ keyPath: KeyPath) -> Void
// )
}
public extension MigrationMappingProvider {
// func migrate(from oldObject: SourceType, to newObject: DestinationType, transaction: UnsafeDataTransaction) {
//
//
// }
//
// func forEachPropertyMapping(from oldObject: SourceType, to newObject: DestinationType, removed: (_ keyPath: KeyPath) -> Void, added: (_ keyPath: KeyPath) -> Void, transformed: (_ keyPath: KeyPath) -> Void) {
//
// let oldAttributes = oldObject.cs_toRaw().entity.attributesByName
// let newAttributes = newObject.cs_toRaw().entity.attributesByName
// let oldAttributeKeys = Set(oldAttributes.keys)
// let newAttributeKeys = Set(newAttributes.keys)
// for keyPath in
// }
}
public extension MigrationMappingProvider {
}
// MARK: - UnsafeMigrationProxyObject
public final class UnsafeMigrationProxyObject {
public subscript(kvcKey: KeyPath) -> CoreDataNativeType? {
get {
return self.rawObject.cs_accessValueForKVCKey(kvcKey)
}
set {
self.rawObject.cs_setValue(newValue, forKVCKey: kvcKey)
}
}
// MARK: Internal
internal init(_ rawObject: NSManagedObject) {
self.rawObject = rawObject
}
// MARK: Private
private let rawObject: NSManagedObject
}