File tree Expand file tree Collapse file tree
CoreDataMigration-Example/CoreData/Migration Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -169,6 +169,16 @@ class CoreDataMigrationModel {
169169
170170 return [ step] + nextStep
171171 }
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+ }
172182}
173183
174184// MARK: - Source
Original file line number Diff line number Diff line change @@ -80,20 +80,12 @@ class CoreDataMigrator {
8080 // MARK: - WAL
8181
8282 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 {
9284 return
9385 }
9486
9587 do {
96- let model = currentCoreDataStoreMigrationVersionModel . managedObjectModel ( )
88+ let model = migrationModel . managedObjectModel ( )
9789 let persistentStoreCoordinator = NSPersistentStoreCoordinator ( managedObjectModel: model)
9890
9991 let options = [ NSSQLitePragmasOption: [ " journal_mode " : " DELETE " ] ]
You can’t perform that action at this time.
0 commit comments