2011-04-24 95 views

回答

0

我能想到這樣做的最好的辦法是通過添加一個屬性到Conversation實體,稱爲lastMessageSentDate和每一個Message進來,被添加到一個Conversation時間,設置該對話的lastMessageSentDate到該消息的sentDate。我也可能想要爲Conversation實體添加一個名爲lastMessageText的屬性,因爲我想在ConversationsViewController上顯示對話最後一條消息的文本(就像本機iPhone消息應用程序一樣),並且這樣做會讓我不必爲Message做另一個核心數據提取。

其實,我只是有個主意!根據Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators,我可以按[email protected]排序Conversation s。

+0

您的第一個想法可能更有效,因爲它消除了每個Conversation.messages集合每次計算最大日期的需要當你獲取對話! – octy 2011-06-13 16:11:02

+0

或只在'Conversation'中有'lastMessage'而不是'lastMessageSentDate'和'lastMessageText' :) – 2012-04-16 11:02:52

+2

@MattDiPasquale我試過了你的想法。它沒有工作。看到相關的問題:http://stackoverflow.com/questions/12748852/how-to-sort-core-data-results-based-on-an-attribute-of-related-object-collection – Jaanus 2012-10-05 15:32:59