Coredata 永続ストアの問題を (おそらく) 簡単に修正できます。
私はそれを作成しました:
- (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;
}
URLを使用してdummyURL.sqlite
私はプロジェクトで作業した最初の日にこれを行いましたが、名前を変更するのを忘れていました..現在、現在のすべてのテストデバイス (4) は、アプリケーションを使用して 2 か月以上使用され、多くのデータを収集し、馬鹿げたURL^^
更新私は永続的なストアの移行についていくつかの調査を行い、この関数を書きました:
-(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];
}
質問1 will this work or will i lose some data with that?
質問2 afterwards will i just have to change the appendString in my persistenstore function?