核心数据:按关系属性排序

发布于 2024-11-02 19:06:01 字数 337 浏览 5 评论 0原文

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

我有一个 Conversation 实体和一个带有 sentDate 属性的 Message 实体。每个Conversation可以有许多Message。如何获取按最早的消息sentDate排序的对话

I'm building an open-source clone of iPhone's native Messages app called AcaniChat on GitHub.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书信已泛黄 2024-11-09 19:06:01

我能想到的最好方法是向名为 lastMessageSentDateConversation 实体添加一个属性,并且每次 Message 传入时添加到对话,将该对话的lastMessageSentDate设置为该消息的sentDate。我可能还想向 Conversation 实体添加一个名为 lastMessageText 的属性,因为我想在 上显示对话的最后一条消息的文本>ConversationsViewController(就像原生 iPhone 消息应用程序一样),这样做将使我不必为 Message 执行另一次核心数据获取。

其实我只是有一个想法!也许我可以按 [email protected] 对对话进行排序],根据Xcode 文档:键值编码编程指南:集合运算符

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.

Actually, I just had an idea! Maybe I can sort Conversations by [email protected], according to Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文