我有一个(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