How to remove coredata from iphone

Do you know how you can Reset coredata storage on an iPhone simulator when you change the structure of an entity?

Do I need to perform a similar process when I created a new version of my main data store, different from what I actually ran on my iPhone? If so, how please?

thanks

+4
source share
4 answers

Just for convenience, until you specify a way to delete persistent storage through your application, you can simply delete the application from your phone. (Hold your finger on the home screen until the icons vibrate, and then press x on your application.) Then, when your phone is connected to your Mac, select "Product"> "Run in Xcode" and it will reinstall your application on the phone, but with empty data directories.

For deployment, of course, you need to come up with a way to do this without uninstalling the application, if you ever change your data model after deployment (assume you do). Data transfer is the best option, but if all else fails, you can delete the persistent storage file. It would be preferable to ask for user approval before this. If they have important data, they may refuse and possibly return the old version of your application to view the data and transfer it manually, or they may wait until you release version 2.0.1, which corrects the data transfer error.

+9
source

Here is the routine that I use to reset my application contents. It deletes the repository and any other saved file.

- (void) resetContent { NSFileManager *localFileManager = [[NSFileManager alloc] init]; NSString * rootDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSURL *rootURL = [NSURL fileURLWithPath:rootDir isDirectory:YES]; NSArray *content = [localFileManager contentsOfDirectoryAtURL:rootURL includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsSubdirectoryDescendants error:NULL]; for (NSURL *itemURL in content) { [localFileManager removeItemAtURL:itemURL error:NULL]; } [localFileManager release]; } 

If you only want to erase the repository, since you know its file name, you can refrain from listing the contents of the document directory:

 - (void) resetContent { NSFileManager *localFileManager = [[NSFileManager alloc] init]; NSString * rootDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSURL *rootURL = [NSURL fileURLWithPath:rootDir isDirectory:YES]; NSURL *storeURL = [rootURL URLByAppendingPathComponent:@"myStore.sqlite"]; [localFileManager removeItemAtURL:storeURL error:NULL]; [localFileManager release]; } 

But note that in many cases it’s better to transfer your store when you change your model, rather than delete it.

+6
source

find your application in /Users/username/Library/Application Support/iPhone Simulator/4.3.2 (iOS version may vary) and delete the .sqlite file

+1
source

You can see the path that is sent to persistentStoreCoordinator during configuration and delete this file. The usual approach that I used is that I configured the repository for automatic migration, and if that fails, I will remove the repository and try again to create a persistent StoreCoordinator that will use the empty path.

Do not forget that you may need to overwrite everything that is stored in the old database.

0
source

All Articles