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

@@ -38,23 +38,29 @@ internal extension NSEntityDescription {
guard let userInfo = self.userInfo,
let typeName = userInfo[UserInfoKey.CoreStoreManagedObjectTypeName] as! String?,
let entityName = userInfo[UserInfoKey.CoreStoreManagedObjectEntityName] as! String? else {
let entityName = userInfo[UserInfoKey.CoreStoreManagedObjectEntityName] as! String?,
let isAbstract = userInfo[UserInfoKey.CoreStoreManagedObjectIsAbstract] as! Bool? else {
return nil
}
return CoreStoreSchema.AnyEntity(
type: NSClassFromString(typeName) as! CoreStoreObject.Type,
entityName: entityName
entityName: entityName,
isAbstract: isAbstract,
versionHashModifier: userInfo[UserInfoKey.CoreStoreManagedObjectVersionHashModifier] as! String?
)
}
set {
if let newValue = newValue {
self.userInfo = [
var userInfo: [AnyHashable : Any] = [
UserInfoKey.CoreStoreManagedObjectTypeName: NSStringFromClass(newValue.type),
UserInfoKey.CoreStoreManagedObjectEntityName: newValue.entityName
UserInfoKey.CoreStoreManagedObjectEntityName: newValue.entityName,
UserInfoKey.CoreStoreManagedObjectIsAbstract: newValue.isAbstract
]
userInfo[UserInfoKey.CoreStoreManagedObjectVersionHashModifier] = newValue.versionHashModifier
self.userInfo = userInfo
}
else {
@@ -72,5 +78,7 @@ internal extension NSEntityDescription {
fileprivate static let CoreStoreManagedObjectTypeName = "CoreStoreManagedObjectTypeName"
fileprivate static let CoreStoreManagedObjectEntityName = "CoreStoreManagedObjectEntityName"
fileprivate static let CoreStoreManagedObjectIsAbstract = "CoreStoreManagedObjectIsAbstract"
fileprivate static let CoreStoreManagedObjectVersionHashModifier = "CoreStoreManagedObjectVersionHashModifier"
}
}

View File

@@ -48,6 +48,25 @@ internal extension NSManagedObject {
}
return nil
}
@nonobjc
internal func isEditableInContext() -> Bool? {
guard let context = self.managedObjectContext else {
return nil
}
if context.isTransactionContext {
return true
}
if context.isDataStackContext {
return false
}
return nil
}
// TODO: test before release (rolled back)
// @nonobjc
// internal static func cs_swizzleMethodsForLogging() {