我有一個(proably)簡單的解決問題,我coredata持久化存儲。使用url dummyURL.sqlite
重命名persistentstore協調URL
我這樣做在第一天與項目工作
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (persistentStoreCoordinator != nil)
{
return persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"dummyURL.sqlite"];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error])
{
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
return persistentStoreCoordinator;
}
,又忘記將其重命名..現在我所有的電流測試設備:
我創造了它與(4)已使用超過2個月,使用應用程序,收集大量的數據,並存儲它與一個愚蠢的網址^^
UPDATE我做了一些研究遷移的持久存儲和寫這個函數:
-(void)migrate{
NSPersistentStoreCoordinator *psc = [self.dataHandler.managedObjectContext persistentStoreCoordinator];
NSURL *oldURL = [psc URLForPersistentStore:[[psc persistentStores]objectAtIndex:0]];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSURL *newURL = [[appDelegate applicationDocumentsDirectory] URLByAppendingPathComponent:@"database.sqlite"];
NSError *error = nil;
NSPersistentStore *oldStore = [psc persistentStoreForURL:oldURL];
NSPersistentStore *newStore = [psc migratePersistentStore:sqliStoreOld
toURL:newURL
options:nil
withType:NSSQLiteStoreType
error:&error];
}
問題1will this work or will i lose some data with that?
問題2afterwards will i just have to change the appendString in my persistenstore function?
感謝您的快速答覆。我對persistentstore概念有點黑幕(這就是爲什麼我沒有創建後觸摸它了)...... 即時通訊目前正在探索'migratePersistentStore'但恐怕實際嘗試,因爲它dataloss ..:/ 會在哪裏我把一個遷移代碼? – 2012-04-18 16:23:19