- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; } NSURL *oldStoreURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"Test.sqlite"]; NSURL *storeURL = [NSURL fileURLWithPath: [[self applicationSupportDirectory] stringByAppendingPathComponent: @"Test.sqlite"]]; NSFileManager* fileManager = [NSFileManager defaultManager]; NSError *error = nil; NSString *oldString = [oldStoreURL path]; NSString *newString = [storeURL path]; if([fileManager fileExistsAtPath:oldString]) { if (![fileManager moveItemAtPath:oldString toPath:newString error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } NSString *oldString2 = [oldString stringByAppendingString:@"-shm"]; NSString *newString2 = [newString stringByAppendingString:@"-shm"]; if (![fileManager moveItemAtPath:oldString2 toPath:newString2 error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } oldString2 = [oldString stringByAppendingString:@"-wal"]; newString2 = [newString stringByAppendingString:@"-wal"]; if (![fileManager moveItemAtPath:oldString2 toPath:newString2 error:&error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } _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; }