RESTKit:对Persistent Store进行细微更改

时间:2014-05-22 17:22:49

标签: ios core-data restkit

如果向任何实体添加属性,我必须删除并重新安装应用程序,因为它崩溃了。我的印象是,下面的选项将允许我对持久性商店进行微小的更改?

- (id)optionsForSqliteStore {
    return @{
             NSInferMappingModelAutomaticallyOption: @YES,
             NSMigratePersistentStoresAutomaticallyOption: @YES
             };
}

- (RKManagedObjectStore *)setupCoreDataWithRESTKit
{

    NSError * error;
    NSURL * modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"App" ofType:@"momd"]];
    NSManagedObjectModel * managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL] mutableCopy];
    self.managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];


    [self.managedObjectStore createPersistentStoreCoordinator];

    NSArray * searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString * documentPath = [searchPaths objectAtIndex:0];
    NSPersistentStore * persistentStore = [self.managedObjectStore addSQLitePersistentStoreAtPath:[NSString stringWithFormat:@"/App.sqlite" fromSeedDatabaseAtPath:nil withConfiguration:nil options:[self optionsForSqliteStore] error:&error];
    NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);

    NSLog(@"Path: %@", [NSString stringWithFormat:@"%@/App%@.sqlite", documentPath, [TBSPersistence username]]);

    if(!persistentStore){
        NSLog(@"Failed to add persistent store: %@", error);
    }

    [self.managedObjectStore createManagedObjectContexts];

    return self.managedObjectStore;

}

这是日志:

014-05-22 10:12:23.631 App[479:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to add persistent store with error: Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn’t be completed. (Cocoa error 134130.)" UserInfo=0x15ea8ee0 {URL=file:///var/mobile/Applications/4BA83C9C-E488-4B3D-B6CC-2CC39CC41AC5/Documents/App.sqlite, metadata={
    NSPersistenceFrameworkVersion = 479;
    NSStoreModelVersionHashes =     {
      // Here listed are all the Entities...
    };
    NSStoreModelVersionHashesVersion = 3;
    NSStoreModelVersionIdentifiers =     (
        ""
    );
    NSStoreType = SQLite;
    NSStoreUUID = "12CC0291-F86F-43B6-A762-873B304C5E6F";
    "_NSAutoVacuumLevel" = 2;
}, reason=Can't find model for source store}'

1 个答案:

答案 0 :(得分:1)

这取决于......

您需要对模型进行版本化,以便可以量化差异,并且需要在自动迁移的范围内进行更改(检查文档,但不能删除,更改数据类型,......)。