2011-04-24 6 views
1

나는 open-source clone of iPhone's native Messages app called AcaniChat on GitHub을 건축 중입니다.핵심 데이터 : 관계의 속성으로 정렬

저는 Conversation 엔티티이고 Message 엔티티는 sentDate입니다. Conversation은 각각 Message을 가질 수 있습니다. Conversation을 가장 오래된 것 중 sentDate 순으로 가져 오는 방법은 Message입니까? 그 대화의 lastMessageSentDate 그 메시지의 sentDate에 설정하는 Message이 들어오는와 Conversation에 추가됩니다 때마다 lastMessageSentDate라고 내가이 일을 생각할 수

+0

비슷한 해결책을 게시했습니다 : http://stackoverflow.com/a/11550855/306764 –

답변

0

가장 좋은 방법은 Conversation 엔티티에 속성을 추가하는 것입니다. 또한 ConversationsViewController (지난 네이티브 iPhone 메시지 앱처럼) 대화의 마지막 메시지 텍스트를 표시하고 싶기 때문에 lastMessageText이라는 속성을 Conversation 엔티티에 추가하려고합니다. Message에 대한 다른 핵심 데이터 가져 오기를 수행하지 않아도됩니다.

사실, 방금 아이디어가 있습니다! 어쩌면 Xcode Documentation: Key-Value Coding Programming Guide: Collection Operators에 따라 [email protected]에 의해 Conversation을 분류 할 수 있습니다.

+0

첫 번째 아이디어는 각 Conversation.messages 컬렉션의 최대 날짜를 계산할 필요가 없기 때문에 더 효율적일 수 있습니다. 대화를 가져올 시간이야! – octy

+0

아니면 그냥'lastMessageSentDate'와'lastMessageText' 대신'Conversation'에서'lastMessage'를 가졌습니다 :) –

+2

@MattDiPasquale 당신의 아이디어를 시도했습니다. 그것은 작동하지 않았다. 관련 질문보기 : http://stackoverflow.com/questions/12748852/how-to-sort-core-data-results-based-on-an-attribute-of-related-object-collection – Jaanus