Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove core data model on iOS app update

My question is related to migration. I cannot do a lightweight migration as there are a lot of changes with attribute types and new relationships. I don't have time for a heavy weight migration since the code is not mine and needs faster delivery.

The workaround, which could work is when the app is upgraded, app should remove the old data and data model as the data is of no use and can be downloaded from the server again. On the app did finish launching, get the .db URL and just remove it and recreate it for the very first time after the upgrade?

After some research, all the methods are pointed to light weight migration. If there is a better way please assist.

like image 598
nr5 Avatar asked Dec 16 '25 17:12

nr5


1 Answers

-(void) removeCoreDataAndReset{

      NSError *error;
      NSPersistentStoreCoordinator *storeCoordinator = storeCordinator;
     for (NSPersistentStore *store in storeCoordinator.persistentStores) {
          [storeCoordinator removePersistentStore:store error:&error];
          [[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:&error];
     }
  // Initialise managedobjectcontext , Store Coordinator etc
} 

Reinitialise all after this method as you do in statrt

like image 124
MOHAMMAD ISHAQ Avatar answered Dec 19 '25 05:12

MOHAMMAD ISHAQ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!