我是第一次使用coredata,我必须从文档目录中的iCloud备份限制sqlite db文件,我使用下面的代码完成了它
-(id)init
{
if((self = [super init]))
{
NSURL* documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL* modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
NSURL* giveForwardSqliteURL = [documentsDirectoryURL URLByAppendingPathComponent:@"InfoCollection.sqlite"];
NSError* error;
m_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
m_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:m_managedObjectModel];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if ([m_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:giveForwardSqliteURL options:options error:&error])
{
m_managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
[m_managedObjectContext setPersistentStoreCoordinator:m_persistentStoreCoordinator];
[self addSkipBackupAttributeToItemAtPath:giveForwardSqliteURL];
}
else
{
NSLog(@"Failed to create or open database: %@", …Run Code Online (Sandbox Code Playgroud)