diff --git a/Sources/ManagedModels/SchemaCompatibility/NSManagedObjectModel+Data.swift b/Sources/ManagedModels/SchemaCompatibility/NSManagedObjectModel+Data.swift index 81e56ff..c8c1863 100644 --- a/Sources/ManagedModels/SchemaCompatibility/NSManagedObjectModel+Data.swift +++ b/Sources/ManagedModels/SchemaCompatibility/NSManagedObjectModel+Data.swift @@ -11,6 +11,12 @@ public extension NSManagedObjectModel { // - encodingVersion // - version + @available(*, deprecated, renamed: "model(for:)", message: + """ + Entities can only be used in one NSManagedObjectModel, use the `model(for:)` + static function to get access to s ahred, cached model. + """ + ) @inlinable convenience init(_ entities: NSEntityDescription..., version: Schema.Version = Version(1, 0, 0)) @@ -19,6 +25,12 @@ public extension NSManagedObjectModel { self.entities = entities } + @available(*, deprecated, renamed: "model(for:)", message: + """ + Entities can only be used in one NSManagedObjectModel, use the `model(for:)` + static function to get access to s ahred, cached model. + """ + ) convenience init(_ types: [ any PersistentModel.Type ], version: Schema.Version = Version(1, 0, 0)) { @@ -26,6 +38,12 @@ public extension NSManagedObjectModel { self.entities = SchemaBuilder.shared.lookupAllEntities(for: types) } + @available(*, deprecated, renamed: "model(for:)", message: + """ + Entities can only be used in one NSManagedObjectModel, use the `model(for:)` + static function to get access to s ahred, cached model. + """ + ) @inlinable convenience init(versionedSchema: any VersionedSchema.Type) { self.init(versionedSchema.models, @@ -39,8 +57,8 @@ public extension NSManagedObjectModel { private let lock = NSLock() private var map = [ Set : NSManagedObjectModel ]() -extension NSManagedObjectModel { - +public extension NSManagedObjectModel { + /// A cached version of the initializer. static func model(for types: [ any PersistentModel.Type ]) -> NSManagedObjectModel @@ -61,7 +79,8 @@ extension NSManagedObjectModel { let mom : NSManagedObjectModel if let cachedMOM { mom = cachedMOM } else { - mom = NSManagedObjectModel(types) + mom = NSManagedObjectModel() + mom.entities = SchemaBuilder.shared.lookupAllEntities(for: types) map[typeIDs] = mom } lock.unlock()