I keep on getting “save operation failure” after any change on my Xcode Data Model

后端 未结 8 1641
囚心锁ツ
囚心锁ツ 2020-12-07 17:00

I started using Core Data for iPhone development. I started out by creating a very simple entity (called Evaluation) with just one string property (called evaluationTopic).

相关标签:
8条回答
  • 2020-12-07 17:25

    if you are running this on the simulator/iphone, also uninstall the app too. worked for me on the simulator only after i deleted the app!

    0 讨论(0)
  • 2020-12-07 17:29

    You could also try "Reset Content and Settings..." in the Simulator. That's what worked for me.

    0 讨论(0)
  • 2020-12-07 17:38

    If you are only getting this error in the Simulator then you have changed your data model and it hasn't deleted the sqlite file that you were previously using.

    So go to: ~/Library/Application Support/iPhone Simulator/User/Applications/

    Then look through the HEX-named folders until you see your app. Open the Documents directory and delete the sqlite file. The error should go away.

    0 讨论(0)
  • 2020-12-07 17:39

    Do you have NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption options set when you create your persistentStoreCoordinator in the App Delegate?

    - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    
        if (persistentStoreCoordinator != nil) {
            return persistentStoreCoordinator;
        }
    
        NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"database.sqlite"]];
    
        NSError *error = nil;
        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                 [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                 [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
        persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
        if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
            // Handle error
        }    
    
        return persistentStoreCoordinator;
    }
    
    0 讨论(0)
  • 2020-12-07 17:39

    Had same issue and it use to work, until I copied the code to another folder in finder and started editing that project, starting getting the error. What fixed it was my other project had a storecordinator with name xyz.sqlite, the "new" project I was working on had same name, had to change it to xyzv2.sqlite (something like that). Found answer here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/27268-nspersistentstorecoordinator-has-no-persistent-stores.html

    0 讨论(0)
  • 2020-12-07 17:43

    Deleting and re-installing the app in both, simulator and device, worked for me.

    0 讨论(0)
提交回复
热议问题