Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created February 4, 2014 01:35
Show Gist options
  • Save keicoder/8795938 to your computer and use it in GitHub Desktop.
Save keicoder/8795938 to your computer and use it in GitHub Desktop.
objective-c : Core Data Lightweight Migration & delete journal mode
//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);
}
}
}
@pixnbit
Copy link

pixnbit commented Aug 16, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment