ITeye博客

为CoreData添加版本管理

mrjeye · 2012-03-30 10:32 · iphone · 移动开发 · Markdown


/**
 Returns the persistent store coordinator for the application.
 If the coordinator doesn't already exist, it is created and the application's store added to it.
 */
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    if (persistentStoreCoordinator_ != nil) {
        return persistentStoreCoordinator_;
    }
    
    NSURL *storeURL = [[self applicationdocumentsdirectory] URLByAppendingPathComponent:@"golf.sqlite"];
    
    NSError *error = nil;
    persistentStoreCoordinator_ = [[nspersistentstorecoordinator alloc] initWithManagedObjectModel:[self managedobjectmodel]];
    
    
    NSDictionary *options = [nsdictionary dictionarywithobjectsandkeys:
                             [nsnumber numberwithbool:yes], NSMigratePersistentStoresAutomaticallyOption,
                             [nsnumber numberwithbool:yes], NSInferMappingModelAutomaticallyOption, nil]; 
    
    if (![persistentstorecoordinator_ addpersistentstorewithtype:nssqlitestoretype
                                                   configuration:nil 
                                                             url:storeurl 
                                                         options:options 
                                                           error:&error]) {
        
        NSLog(@"Unresolved error %@, %@", error, [error userinfo]);
        abort();
    }    
    
    return persistentStoreCoordinator_;
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。