mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-24 18:31:41 +01:00
uniquify subclass names across model versions
This commit is contained in:
@@ -13,6 +13,12 @@ import CoreData
|
|||||||
|
|
||||||
@objc internal class CoreStoreManagedObject: NSManagedObject {
|
@objc internal class CoreStoreManagedObject: NSManagedObject {
|
||||||
|
|
||||||
|
@nonobjc @inline(__always)
|
||||||
|
internal static func cs_subclassName(for entity: DynamicEntity, in modelVersion: ModelVersion) -> String {
|
||||||
|
|
||||||
|
return "_\(NSStringFromClass(CoreStoreManagedObject.self))__\(modelVersion)__\(NSStringFromClass(entity.type))__\(entity.entityName)"
|
||||||
|
}
|
||||||
|
|
||||||
@nonobjc
|
@nonobjc
|
||||||
internal class func cs_setKeyPathsForValuesAffectingKeys(_ keyPathsForValuesAffectingKeys: [KeyPath: Set<KeyPath>], for managedObjectClass: CoreStoreManagedObject.Type) {
|
internal class func cs_setKeyPathsForValuesAffectingKeys(_ keyPathsForValuesAffectingKeys: [KeyPath: Set<KeyPath>], for managedObjectClass: CoreStoreManagedObject.Type) {
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
|
|
||||||
let entityDescription = self.entityDescription(
|
let entityDescription = self.entityDescription(
|
||||||
for: entity,
|
for: entity,
|
||||||
initializer: CoreStoreSchema.firstPassCreateEntityDescription
|
initializer: CoreStoreSchema.firstPassCreateEntityDescription(from:in:)
|
||||||
)
|
)
|
||||||
entityDescriptionsByEntity[entity] = (entityDescription.copy() as! NSEntityDescription)
|
entityDescriptionsByEntity[entity] = (entityDescription.copy() as! NSEntityDescription)
|
||||||
}
|
}
|
||||||
@@ -250,25 +250,26 @@ public final class CoreStoreSchema: DynamicSchema {
|
|||||||
private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:]
|
||||||
private weak var cachedRawModel: NSManagedObjectModel?
|
private weak var cachedRawModel: NSManagedObjectModel?
|
||||||
|
|
||||||
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity) -> NSEntityDescription) -> NSEntityDescription {
|
private func entityDescription(for entity: DynamicEntity, initializer: (DynamicEntity, ModelVersion) -> NSEntityDescription) -> NSEntityDescription {
|
||||||
|
|
||||||
if let cachedEntityDescription = self.entityDescriptionsByEntity[entity] {
|
if let cachedEntityDescription = self.entityDescriptionsByEntity[entity] {
|
||||||
|
|
||||||
return cachedEntityDescription
|
return cachedEntityDescription
|
||||||
}
|
}
|
||||||
let entityDescription = withoutActuallyEscaping(initializer, do: { $0(entity) })
|
let modelVersion = self.modelVersion
|
||||||
|
let entityDescription = withoutActuallyEscaping(initializer, do: { $0(entity, modelVersion) })
|
||||||
self.entityDescriptionsByEntity[entity] = entityDescription
|
self.entityDescriptionsByEntity[entity] = entityDescription
|
||||||
return entityDescription
|
return entityDescription
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func firstPassCreateEntityDescription(from entity: DynamicEntity) -> NSEntityDescription {
|
private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> NSEntityDescription {
|
||||||
|
|
||||||
let entityDescription = NSEntityDescription()
|
let entityDescription = NSEntityDescription()
|
||||||
entityDescription.coreStoreEntity = entity
|
entityDescription.coreStoreEntity = entity
|
||||||
entityDescription.name = entity.entityName
|
entityDescription.name = entity.entityName
|
||||||
entityDescription.isAbstract = entity.isAbstract
|
entityDescription.isAbstract = entity.isAbstract
|
||||||
entityDescription.versionHashModifier = entity.versionHashModifier
|
entityDescription.versionHashModifier = entity.versionHashModifier
|
||||||
entityDescription.managedObjectClassName = "\(NSStringFromClass(CoreStoreManagedObject.self)).\(NSStringFromClass(entity.type)).\(entity.entityName)"
|
entityDescription.managedObjectClassName = CoreStoreManagedObject.cs_subclassName(for: entity, in: modelVersion)
|
||||||
|
|
||||||
var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] = [:]
|
var keyPathsByAffectedKeyPaths: [KeyPath: Set<KeyPath>] = [:]
|
||||||
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
|
func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {
|
||||||
|
|||||||
Reference in New Issue
Block a user