问题
I am writing my first core data app. For some reason, my edits are gone after quitting and restarting the app. Saving, closing window, and re-opening (without quitting) retains the data. If I open the saved file in textedit, I see my edited field. Something must go wrong during reading. Perhaps I forgot to change a setting somewhere? Does anyone recognize this behavior?
回答1:
Are you saving the NSManagedObjectContext after making changes to your model objects?
Try
NSError *error;
if (![myContext save:&error]) {
// Handle error
}
The save message returns a BOOL for success. You should check that value to see if the save was successful. If not, the NSError reference that you pass in will contain information on why the save may have failed.
If you post your code, I might be able to help further.
回答2:
The array controllers should have "prepares content" turned on. Otherwise, loading does not populate the array, and another save permentently removes the edits!
来源:https://stackoverflow.com/questions/11700502/core-data-app-does-not-save-my-data-why