Skip to content

Commit

Permalink
Add a default configuration if none was provided
Browse files Browse the repository at this point in the history
...
  • Loading branch information
helje5 committed Sep 30, 2023
1 parent 0a942f3 commit 77ede3b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/ManagedModels/Container/NSPersistentContainer+Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 77ede3b

Please sign in to comment.