For each application update, I would like to completely erase the entire Core Data database, and then configure it again. I did not succeed. I tried different things, this seems to be the closest that I came. I found several SO posts, but none of the solutions worked for my purposes.
I use MagicalRecord , which provides several short methods for getting various objects. Here is my code:
if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"buildVersion"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]) { NSPersistentStore *store = [NSPersistentStore defaultPersistentStore]; NSError *error; NSURL *storeURL = [NSPersistentStore defaultLocalStoreUrl]; NSPersistentStoreCoordinator *storeCoordinator = [NSPersistentStoreCoordinator defaultStoreCoordinator]; [storeCoordinator removePersistentStore:store error:&error]; [[NSFileManager defaultManager] removeItemAtPath:storeURL.path error:&error]; [[NSUserDefaults standardUserDefaults] setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] forKey:@"buildVersion"]; } [MagicalRecord setupCoreDataStack];
source share