核心数据:按关系属性排序 [英] Core Data: Sort by Relationship's Attribute

查看:84
本文介绍了核心数据:按关系属性排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 iPhone的本地消息应用程序的开源克隆,名为GitHub上的AcaniChat

我有一个会话实体和一个 Message 实体, sentDate 属性。每个会话可以有许多消息。如何获取会话,按其最旧的消息 sentDate $ c>?

I have a Conversation entity and a Message entity with a sentDate attribute. Each Conversation can have many Messages. How do I fetch Conversations sorted by the sentDate of it's oldest Message?

推荐答案

我能想到的最好方法是在对话实体,称为 lastMessageSentDate ,每次出现 Message 并将其添加到对话,将对话的 lastMessageSentDate 设置为邮件的 sentDate 。我可能还想向 Conversation 实体添加一个名为 lastMessageText 的属性,因为我想显示在 ConversationsViewController 上进行对话的最后一条消息的文本(就像本机iPhone Messages应用程序所做的那样),这样做将使我不必再为消息

The best way I can think of doing this is by adding an attribute to the Conversation entity called lastMessageSentDate and, every time a Message comes in and gets added to a Conversation, setting that conversation's lastMessageSentDate to that message's sentDate. I'll also probably want to add an attribute called lastMessageText to the Conversation entity as well because I want to show the text of the last message for a conversation on the ConversationsViewController (just like the native iPhone Messages app does), and doing so will save me from having to do another Core Data fetch for the Message.

实际上,我只是有一个主意!根据 messages。@ max.sortedDate 对会话进行排序。 /developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.html#//apple_ref/doc/uid/20002176-BAJEAIEE rel = nofollow> Xcode文档:键值编码编程指南:集合运算符

Actually, I just had an idea! Maybe I can sort Conversations by messages.@max.sortedDate, according to Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators.

这篇关于核心数据:按关系属性排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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