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] 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 {