1
1
//
2
2
// Created by Helge Heß.
3
- // Copyright © 2023 ZeeZide GmbH.
3
+ // Copyright © 2023-2024 ZeeZide GmbH.
4
4
//
5
5
6
6
import CoreData
@@ -27,9 +27,21 @@ extension NSPersistentContainer {
27
27
precondition ( migrationPlan == nil , " Migration plans not yet supported " )
28
28
29
29
let combinedModel : NSManagedObjectModel = {
30
- let allModels = [ model ] + configurations. compactMap { $0. schema }
30
+ guard let firstConfig = configurations. first else { return model }
31
+ if configurations. count == 1 ,
32
+ firstConfig. schema == nil || firstConfig. schema == model
33
+ {
34
+ return model
35
+ }
36
+
37
+ var allModels = [ ObjectIdentifier : NSManagedObjectModel ] ( )
38
+ allModels [ ObjectIdentifier ( model) ] = model
39
+ for config in configurations {
40
+ guard let model = config. schema else { continue }
41
+ allModels [ ObjectIdentifier ( model) ] = model
42
+ }
31
43
guard allModels. count > 1 else { return model }
32
- let merged = NSManagedObjectModel ( byMerging: allModels)
44
+ let merged = NSManagedObjectModel ( byMerging: Array ( allModels. values ) )
33
45
assert ( merged != nil , " Could not combine object models: \( allModels) " )
34
46
return merged ?? model
35
47
} ( )
@@ -84,6 +96,7 @@ extension NSPersistentContainer {
84
96
85
97
public extension NSPersistentContainer {
86
98
99
+ @inlinable
87
100
convenience init ( for model : NSManagedObjectModel ,
88
101
migrationPlan : SchemaMigrationPlan . Type ? = nil ,
89
102
configurations : ModelConfiguration ... ) throws
@@ -92,6 +105,7 @@ public extension NSPersistentContainer {
92
105
configurations: configurations)
93
106
}
94
107
108
+ @inlinable
95
109
convenience init ( for types : any PersistentModel . Type ... ,
96
110
migrationPlan : SchemaMigrationPlan . Type ? = nil ,
97
111
configurations : ModelConfiguration ... ) throws
0 commit comments