I have a (possibly) simple fix problem in my coredata persistent storage.
i created it with
- (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; }
using the URL dummyURL.sqlite
I did this on the first day of working with the project and forgot to rename it. Now all my current test devices (4) have been used for more than 2 months using the application, collecting a lot of data and saving it with a silly url ^^
UPDATE I did some research on persistent storage migration and wrote this function:
-(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]; }
QUESTION 1 will this work or will i lose some data with that?
QUESTION 2 afterwards will i just have to change the appendString in my persistenstore function?
source share