diff --git a/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift b/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift index 50a8e09..b2ca366 100644 --- a/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift +++ b/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift @@ -13,6 +13,11 @@ extension NSPersistentContainer { //@MainActor - TBD :-) @inlinable public var mainContext : NSManagedObjectContext { viewContext } + + @inlinable + public var configurations : [ NSPersistentStoreDescription ] { + persistentStoreDescriptions + } convenience public init(for model : NSManagedObjectModel, @@ -29,11 +34,17 @@ extension NSPersistentContainer { return merged ?? model }() + var configurations = configurations + if configurations.isEmpty { + configurations.append(Self.defaultConfiguration) + } + // TBD: Is this correct? It is the container name, not the configuration // name? let firstName = configurations.first(where: { !$0.name.isEmpty })?.name ?? "ManagedModels" + assert(!configurations.isEmpty) self.init( name: firstName, managedObjectModel: combinedModel @@ -61,6 +72,14 @@ extension NSPersistentContainer { viewContext.automaticallyMergesChangesFromParent = true } + private static var defaultConfiguration : ModelConfiguration { + .init( + path: nil, name: nil, schema: nil, + isStoredInMemoryOnly: false, allowsSave: true, + groupAppContainerIdentifier: nil, cloudKitContainerIdentifier: nil, + groupContainer: .none, cloudKitDatabase: .none + ) + } } public extension NSPersistentContainer { diff --git a/Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift b/Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift index b1547c3..39dd66e 100644 --- a/Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift +++ b/Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift @@ -282,7 +282,7 @@ final class ModelMacroTests: XCTestCase { """ )) - #if true + #if false print("Exploded:---\n") print(explodedSource) print("\n-----") @@ -360,7 +360,7 @@ final class ModelMacroTests: XCTestCase { """ )) - #if true + #if false print("Exploded:---\n") print(explodedSource) print("\n-----")