我应该在持续更新关系中使用FetchedResultsController对象吗? [英] Should I Use a FetchedResultsController for Objects in a Constantly Updating Relationship?

查看:257
本文介绍了我应该在持续更新关系中使用FetchedResultsController对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Coredata模型,一个实体称为对话,另一个实体称为消息。基本上,我需要一种再现iPhone的sms应用程序。

I have a simple Coredata model with one entity called "conversation" and the other one "messages". Basically, I need to kind of reproduce the iPhone sms application.

我从一封邮件到另一封邮件之间具有一对一的关系,一对多关系从一个对话到另一封邮件。

I have a to-one relationship from message to conversation and a to-many from conversation to messages.

Conversation{
    messages<-->>Message.conversation
}

Message{
    conversation<<-->Conversation.messages
}

每次启动我的应用程式时被加载到我的fetchedResultsController。如果我正确理解Coredata如何工作,因为我有一个关系,每个链接到我的谈话的消息将被加载吗?我设置了批量大小,因此我无法同时加载所有对话。

Anytime I launch my app, all my conversation are loaded in my fetchedResultsController. If I understood correctly how Coredata works, as I have a relationship, every messages linked to my conversation will be loaded as well right? I set up a batch size so that I don't load all my conversations at the same time.

我的应用通过长时间拉取请求连接到服务器,因此我可以随时从服务器收到一条消息(将添加到coredata然后我使用NSNotification告诉我的意见附加)。

My app is connected to a server via a long pulling request, so I can receive an message from the server at any time (there will be added to coredata and then I use NSNotification to tell my views something append).

我的问题是这个:当我选择一行时,我在堆栈上推另一个视图,以便我可以看到我的消息。我想知道如何做到这一点,并且有什么原因:

MY problem is this: When I select a row, I push another view on the stack, so that I can see my messages. I was wondering how to do that, and there is why:

•我可以传递给我的视图我的NSSet通过关系给出的消息,对吧?然而,我可以收到一个消息,同时看着那个视图,我如何刷新传递给视图的NSSet?

• I could pass to my view my NSSet of messages given via the relationship, right? however, as I can receive a message, while looking at that view, how do i refresh the NSSet passed to the view?

我也可以使用另一个fetchedresultController视图,但在这种情况下,我会预先加载我的以前的视图中的所有邮件没有理由?我可以告诉coredata不要在我以前的视图中加载它们吗?

• I could also use another fetchedresultController in that view, but in that case, I would be pre-loading all my messages in my previous view for no reason ? Can I tell coredata not to load them in my previous view?

我希望这很清楚。我绝望,我知道在那个网站上有一些专家。如果您需要其他资料,请尽快提供更多资讯。

I hope this was clear enough. I kind of desperate and I know there are some expert on that website. Let me know if you need anything else, I'll try to provide more information as soon as possible.

推荐答案


如果我正确理解Coredata
的工作原理,因为我有一个关系,每个
链接到我的谈话
的消息将被加载吗?

If I understood correctly how Coredata works, as I have a relationship, every messages linked to my conversation will be loaded as well right?

在查询关系之前,不会加载消息对象本身。

The Message objects themselves are not loaded until you query the relationship. Until then they are at most just faults (ghost placeholders.)

通常,你只需要传递 Conversation 对象用户在第一个表中选择。在第二个tableview控制器中,你会问: Conversation 对象是相关的消息。然后你可以将它们排列成一个数组来显示。

Normally, you would simply pass the Conversation object that the user selected in the first table. In the second tableview controller, you would then ask that Conversation object for it's related messages. Then you would sort them into an array for display.

但是,如果您遇到消息关系不断更新的新 Message 对象,那么您可能想使用NSFetchedResultsController(FRC),因为您获得了新更新的 Message 对象的所有自动通知。

However, if you have a circumstance in which the messages relationship is constantly being updated with new Message objects, then you might want to use a NSFetchedResultsController (FRC) just because you get all the automatic notifications of newly updated Message objects.

为此,您将传递如上所述的 Conversation 对象,然后在FRC的谓词中使用它像这样:

To do this, you would pass the Conversation object as above and then use it in the predicate for the FRC like so:

NSPredicate *p=[NSPredicate predicateWithFormat:@"conversation==%@",passedConversationObject];

然后像往常一样实现FRC委托方法。

Then implement the FRC delegate methods as usual.

当然,您可以从上下文中注册 NSManagedObjectContextObjectsDidChangeNotification 的第二个tableview控制器,对于新手,FRC可能更容易。

Of course, you can just register the second tableview controller for NSManagedObjectContextObjectsDidChangeNotification from the context and handle all this directly but for a novice the FRC might be easier.

这篇关于我应该在持续更新关系中使用FetchedResultsController对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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