Created
March 30, 2014 22:40
-
-
Save ap4y/9881152 to your computer and use it in GitHub Desktop.
NSPersistenceStoreCoordinator with SQLStore
This file contains 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
+ (BOOL)addInSQLStorageWithName:(NSString *)dbFileName error:(NSError **)error { | |
if (!defaultCoordinator) { | |
if (error) { | |
NSDictionary *errorInfo = @{ | |
NSLocalizedDescriptionKey: NSLocalizedString(@"Default coordinator is not registered.", nil) | |
}; | |
*error = [NSError errorWithDomain:NSCocoaErrorDomain | |
code:NSCoreDataError | |
userInfo:errorInfo]; | |
} | |
return NO; | |
} | |
NSDictionary *options = @{ | |
NSMigratePersistentStoresAutomaticallyOption: [NSNumber numberWithBool:YES], | |
NSInferMappingModelAutomaticallyOption: [NSNumber numberWithBool:YES] | |
}; | |
NSString *fileName = [NSString stringWithFormat:@"%@.sqlite", dbFileName]; | |
NSArray *pathes = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES); | |
NSString *appPath = [pathes lastObject]; | |
appPath = [appPath stringByAppendingPathComponent:fileName]; | |
NSURL *storeURL = [NSURL fileURLWithPath:appPath isDirectory:NO]; | |
return [defaultCoordinator addPersistentStoreWithType:NSSQLiteStoreType | |
configuration:nil | |
URL:storeURL | |
options:options | |
error:error]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment