diff --git a/Sources/CoreStoreManagedObject.swift b/Sources/CoreStoreManagedObject.swift index f3c3b6c..285596e 100644 --- a/Sources/CoreStoreManagedObject.swift +++ b/Sources/CoreStoreManagedObject.swift @@ -13,6 +13,12 @@ import CoreData @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 internal class func cs_setKeyPathsForValuesAffectingKeys(_ keyPathsForValuesAffectingKeys: [KeyPath: Set], for managedObjectClass: CoreStoreManagedObject.Type) { diff --git a/Sources/CoreStoreSchema.swift b/Sources/CoreStoreSchema.swift index 8d7bc82..32b1d0f 100644 --- a/Sources/CoreStoreSchema.swift +++ b/Sources/CoreStoreSchema.swift @@ -212,7 +212,7 @@ public final class CoreStoreSchema: DynamicSchema { let entityDescription = self.entityDescription( for: entity, - initializer: CoreStoreSchema.firstPassCreateEntityDescription + initializer: CoreStoreSchema.firstPassCreateEntityDescription(from:in:) ) entityDescriptionsByEntity[entity] = (entityDescription.copy() as! NSEntityDescription) } @@ -250,25 +250,26 @@ public final class CoreStoreSchema: DynamicSchema { private var entityDescriptionsByEntity: [DynamicEntity: NSEntityDescription] = [:] 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] { 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 return entityDescription } - private static func firstPassCreateEntityDescription(from entity: DynamicEntity) -> NSEntityDescription { + private static func firstPassCreateEntityDescription(from entity: DynamicEntity, in modelVersion: ModelVersion) -> NSEntityDescription { let entityDescription = NSEntityDescription() entityDescription.coreStoreEntity = entity entityDescription.name = entity.entityName entityDescription.isAbstract = entity.isAbstract 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] = [:] func createProperties(for type: CoreStoreObject.Type) -> [NSPropertyDescription] {