Skip to content

Commit 77ede3b

Browse files
committed
Add a default configuration if none was provided
...
1 parent 0a942f3 commit 77ede3b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/ManagedModels/Container/NSPersistentContainer+Data.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ extension NSPersistentContainer {
3434
return merged ?? model
3535
}()
3636

37+
var configurations = configurations
38+
if configurations.isEmpty {
39+
configurations.append(Self.defaultConfiguration)
40+
}
41+
3742
// TBD: Is this correct? It is the container name, not the configuration
3843
// name?
3944
let firstName = configurations.first(where: { !$0.name.isEmpty })?.name
4045
?? "ManagedModels"
4146

47+
assert(!configurations.isEmpty)
4248
self.init(
4349
name: firstName,
4450
managedObjectModel: combinedModel
@@ -66,6 +72,14 @@ extension NSPersistentContainer {
6672
viewContext.automaticallyMergesChangesFromParent = true
6773
}
6874

75+
private static var defaultConfiguration : ModelConfiguration {
76+
.init(
77+
path: nil, name: nil, schema: nil,
78+
isStoredInMemoryOnly: false, allowsSave: true,
79+
groupAppContainerIdentifier: nil, cloudKitContainerIdentifier: nil,
80+
groupContainer: .none, cloudKitDatabase: .none
81+
)
82+
}
6983
}
7084

7185
public extension NSPersistentContainer {

0 commit comments

Comments
 (0)