CoreData: Fetching an Object from an unsaved Context

柔情痞子 提交于 2019-12-04 23:33:06

问题


after I insert a ManagedObject into a context I'd like to fetch it later but before saving the context (I'd save after all objects are inserted). It appears that querying the context later with a fetch concerning those objects returns nothing if the context wasn't previously saved. Is there a way to save only in the end ?(I guess i can save my objects in an array or dictionary and query that but i thought coredata would do this for me)


回答1:


Try this:

[myFetchRequest setIncludesPendingChanges:YES];

From the documentation:

Sets if, when the fetch is executed, it matches against currently unsaved changes in the managed object context.



来源:https://stackoverflow.com/questions/3235498/coredata-fetching-an-object-from-an-unsaved-context

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