CoreData:从未保存的上下文中获取对象 [英] CoreData: Fetching an Object from an unsaved Context

查看:222
本文介绍了CoreData:从未保存的上下文中获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我插入一个ManagedObject到上下文中,我想在稍后但在保存上下文之前提取它(我会在所有对象插入后保存)。看起来,如果上下文之前未保存,则稍后使用关于这些对象的提取查询上下文不会返回任何内容。
有没有办法只保存到最后?(我想我可以保存我的对象在数组或字典和查询,但我认为coredata会为我这样做)

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)

推荐答案

尝试:

[myFetchRequest setIncludesPendingChanges:YES];

文档


设置当执行提取时,是否与托管对象上下文中当前未保存的更改匹配。

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

这篇关于CoreData:从未保存的上下文中获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆