Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to recreate persistentStore not to be affected by changing .xcdatamodeld
    primarykey
    data
    text
    <p>I'd like to recreate (drop &amp; create) persistentStore not to be affected by changing .xcdatamodeld.</p> <p>I wrote a code persistentStoreCoordinator in AppDelegate likes below:</p> <pre><code>- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; } _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"myproject.sqlite"]; // delete if database exists NSError *error = nil; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) { // if .xcdatamodeld is changed, fail and in here... // if not changed, recreate success. all data removed from database NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } NSArray *stores = [_persistentStoreCoordinator persistentStores]; for (NSPersistentStore *store in stores) { [_persistentStoreCoordinator removePersistentStore:store error:nil]; [[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:nil]; } // newly create database if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&amp;error]) { NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } return _persistentStoreCoordinator; } </code></pre> <p>when I make a change to <code>.xcdatamodeld</code> (ex. adding new column to entity) and reboot simulator, then fail at first <code>addPersistentStoreWithType</code> and log says</p> <pre><code>Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 The operation couldn’t be completed. (Cocoa error 134100.) </code></pre> <p>How can I do that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload