From 0a942f3a0b381a3676ee82b2d0ab74b7160d891f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 30 Sep 2023 17:03:52 +0200 Subject: [PATCH 1/3] Add `configurations` to PC Does return the `NSPersistentStoreDescription`s though. We could alias `NSPersistentStoreDescription` to the `ModelConfiguration`, but we'd need at least a slot for storing the models associated w/ the configuration. --- .../ManagedModels/Container/NSPersistentContainer+Data.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift b/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift index 50a8e09..ea043fd 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, From 77ede3b5c71291b529815e8dd68e6d443526e809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 30 Sep 2023 17:30:09 +0200 Subject: [PATCH 2/3] Add a default configuration if none was provided ... --- .../Container/NSPersistentContainer+Data.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift b/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift index ea043fd..b2ca366 100644 --- a/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift +++ b/Sources/ManagedModels/Container/NSPersistentContainer+Data.swift @@ -34,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 @@ -66,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 { From 82b77f6fd53e9a08de1e5d17880149eff07fb143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Sat, 30 Sep 2023 17:31:10 +0200 Subject: [PATCH 3/3] Drop some prints in test ... --- Tests/ManagedModelMacrosTests/ManagedModelMacrosTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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-----")