Core Data - Re-saving Object in didSave

…衆ロ難τιáo~ 提交于 2019-12-12 02:06:31

问题


I have to check for certain properties after saving the object to the database (I need to make sure first that it's saved on disk). So, I thought that the didSave method of NSManagedObject is the best place to do so.

However, after checking for these properties and changing some of them, I want to re-save the object. So, I call the managed object context to save the object one more time. (I made heavy testing to make sure I won't get into an infinite loop).

Now, the problem is the managed object context doesn't perform the second save. How did I know that? Well, first I checked the hasChanged property of the context for the second save and it returns no. Also, the didSave method is not called one more time due to the re-save.

Is there something I am doing wrong? What's wrong with my algorithm?

Note:

I considered willSave at the beginning but as it turned out, willSave is called before validation. The object may not be saved on disk after all. I need to perform my check and new setting after saving to disk.

来源:https://stackoverflow.com/questions/26697440/core-data-re-saving-object-in-didsave

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