简体   繁体   中英

Is migration always needed?

Right now my code in AppDelegate.m is:

[MagicalRecord setupAutoMigratingCoreDataStack];
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"db.sqlite"];

Does it cost much? Does any code exist like:

if (DB.version == newVersion) {
    [MagicalRecord setupAutoMigratingCoreDataStack];
    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"db.sqlite"];
}
else {
    [MagicalRecord setupCoreDataStack];
    [MagicalRecord setupCoreDataStackWithStoreNamed:@"db.sqlite"];
}

that would save some performance instead of force-migrating every time? Or does MagicalRecord/CoreData handle this if statement internally?

Core Data doesn't do an automatic migration unless it's necessary. The first version doesn't "force" a migration. Core Data always checks to see if it can load the persistent store file using the current version of the data model. The only difference is what happens if the versions don't match. If they do match, there's no additional migration-related work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM