File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
CoreDataMigration-Example/CoreData/Migration Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,16 @@ class CoreDataMigrationModel {
169
169
170
170
return [ step] + nextStep
171
171
}
172
+
173
+ // MARK: - Metadata
174
+
175
+ static func migrationModelCompatibleWithStoreMetadata( _ metadata: [ String : Any ] ) -> CoreDataMigrationModel ? {
176
+ let compatibleMigrationModel = CoreDataMigrationModel . all. first {
177
+ $0. managedObjectModel ( ) . isConfiguration ( withName: nil , compatibleWithStoreMetadata: metadata)
178
+ }
179
+
180
+ return compatibleMigrationModel
181
+ }
172
182
}
173
183
174
184
// MARK: - Source
Original file line number Diff line number Diff line change @@ -80,20 +80,12 @@ class CoreDataMigrator {
80
80
// MARK: - WAL
81
81
82
82
func forceWALCheckpointingForStore( at storeURL: URL ) {
83
- guard let metadata = NSPersistentStoreCoordinator . metadata ( at: storeURL) else {
84
- return
85
- }
86
-
87
- let migrationVersionModel = CoreDataMigrationModel . all. first {
88
- $0. managedObjectModel ( ) . isConfiguration ( withName: nil , compatibleWithStoreMetadata: metadata)
89
- }
90
-
91
- guard let currentCoreDataStoreMigrationVersionModel = migrationVersionModel else {
83
+ guard let metadata = NSPersistentStoreCoordinator . metadata ( at: storeURL) , let migrationModel = CoreDataMigrationModel . migrationModelCompatibleWithStoreMetadata ( metadata) else {
92
84
return
93
85
}
94
86
95
87
do {
96
- let model = currentCoreDataStoreMigrationVersionModel . managedObjectModel ( )
88
+ let model = migrationModel . managedObjectModel ( )
97
89
let persistentStoreCoordinator = NSPersistentStoreCoordinator ( managedObjectModel: model)
98
90
99
91
let options = [ NSSQLitePragmasOption: [ " journal_mode " : " DELETE " ] ]
You can’t perform that action at this time.
0 commit comments