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?
The best way I can think of doing this is by adding an attribute to the
Conversationentity calledlastMessageSentDateand, every time aMessagecomes in and gets added to aConversation, setting that conversation’slastMessageSentDateto that message’ssentDate. I’ll also probably want to add an attribute calledlastMessageTextto theConversationentity as well because I want to show the text of the last message for a conversation on theConversationsViewController(just like the native iPhone Messages app does), and doing so will save me from having to do another Core Data fetch for theMessage.Actually, I just had an idea! Maybe I can sort
Conversations bymessages.@max.sortedDate, according to Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators.