Core data app does not save my data, why?

假装没事ソ 提交于 2019-12-24 09:15:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!