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.
source share