在开发我的应用程序的早期阶段,Core Data
我RestKit
经常大量修改数据模型,发现很少或根本没有考虑迁移。
我希望逻辑是:
IF (there is a foolproof, automatic migration path) THEN
TRY { foolproof path; }
CATCH { brute path; }
ELSE
brute path;
brute path:
IF (SqlLiteDatabase exists) THEN
DELETE IT;
CREATE SqlLiteDatabase;
我现在有什么,老实说,我不明白......
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:[[RestKitClientConfigurator webServiceConfiguration] baseURL]]];
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
[managedObjectStore createPersistentStoreCoordinator];
NSString *storePath = [RKApplicationDataDirectory() stringByAppendingPathComponent:@"CTISDB.sqlite"];
NSString *seedPath = [[NSBundle mainBundle] pathForResource:@"RKSeedDatabase" ofType:@"sqlite"];
NSDictionary *optionsDictionary =
[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
forKey:NSMigratePersistentStoresAutomaticallyOption];
NSError *error;
NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:seedPath withConfiguration:nil options:nil error:&error];
NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
但基本上,我真正想知道的是 - 这不是一个足够普遍的问题(必须不断重置虚拟设备),有一种方法可以告诉Core Data
它只是把它炸毁吗?
如果没有,我错过了这个阻止上述算法实现的操作的复杂性?