Created
February 4, 2014 01:35
-
-
Save keicoder/8795938 to your computer and use it in GitHub Desktop.
objective-c : Core Data Lightweight Migration & delete journal mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Core Data Lightweight Migration & delete journal mode | |
//1. add a model version | |
//select current xcdatamodel -> Editor > Add Model Version -> accept new version name | |
//2. update data model | |
//select new xcdatamodel -> create a new entity -> select the new entity, create an attribute you want | |
//3. update current model version | |
//select current xcdatamodel -> file inspector -> set current model version to new (Model 2) model version | |
//4. add following code for Lightweight Migration (migration can be handled automatically) | |
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES, | |
NSInferMappingModelAutomaticallyOption:@YES} | |
//sample code : | |
- (void)loadStore { | |
if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));} | |
if (_store) { | |
return; // Don’t load store if it’s already loaded | |
} | |
//Core Data Lightweight Migration & delete journal mode | |
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES, | |
NSInferMappingModelAutomaticallyOption:@YES, | |
NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"}}; | |
NSError *error = nil; | |
_store = [_coordinator addPersistentStoreWithType:NSSQLiteStoreType | |
configuration:nil | |
URL:[self storeURL] | |
options:options error:&error]; | |
if (!_store) { | |
NSLog(@"Failed to add store. Error: %@", error);abort(); | |
} else { | |
if (debug==1) { | |
NSLog(@"Successfully added store: %@", _store); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what is NSSQLitePragmasOption: @{@"journal_mode": @"DELETE"} for ?
OK, I figured out, it's for pre iOS 7 bug fix... I don't need it then.