默认情况下,iPhone中的核心数据使用哪个持久存储 [英] Which persistent store is used by default in core data in iPhone

查看:104
本文介绍了默认情况下,iPhone中的核心数据使用哪个持久存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中创建多个持久存储,但我只使用一个持久存储协调器和管理对象模型。现在我的问题是当我调用保存方法在托管对象上下文,其持久存储它将用于保存对象。所以我想指定用于保存对象的持久存储。从数据库中获取对象时,我想确保我的读取查询应该在特定的存储上执行,以便只从该存储中获取对象。任何帮助?

I am creating multiple persistent store in my application, but I am using only one persistent store coordinator and managed object model. Now my question is when I call save method on managed object context, which persistent store it will use to save the object. So I want to specify the persistent store to be used to save the object. Same while fetching the objects from database, I want to ensure that my fetch query should be executed on a particular store so that I get objects from that store only. Any help?

推荐答案

获取不应该是一个问题。可以修改抓取请求,以使用NSFetchRequest上的setAffectedStores:方法搜索特定商店。

Fetching should not be an issue. The fetch request can be modified to search particular stores using the setAffectedStores: method on an NSFetchRequest.

创建对象时,可以将实体分配给特定使用NSManagedObjectContext上的assignObject:toPersisentStore:方法存储。

When you're creating an object, you can assign the entity to a particular store using the assignObject:toPersisentStore: method on NSManagedObjectContext.

对于你的问题,我没有真正的一个默认机制,我知道,您只需要将受影响的商店设置为所有商店:

As to your question, there isn't really a default mechanism that I am aware of, and it may be that you simply need to set the affected stores to all of your stores:

[request setAffectedStores:[NSArray arrayWithObjects:firstStore,secondStore,thirdStore,nil ]];

确保您查找所有正确的地点。

To be sure that you're looking in all the right places.

这篇关于默认情况下,iPhone中的核心数据使用哪个持久存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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