0

I am writing a demo messaging app to learn Core Data. In my model, an entity Conversation has a to-many relationship messages to Message. A Message has a timeStamp. I intend to display these messages in a collection view/table view with an NSFetchedResultsController. I want to know what would be the most efficient way to sort these messages. I searched around and found that I could sort the messages using:

  • an NSSortDescriptor on message.timeStamp
  • making the messages relationship ordered
  • adding a sequence property to message

What should be the best way to sort the messages?

4

1 回答 1

1

排序顺序应该反映您的应用程序逻辑:
在对话中移动消息是否合乎逻辑?(如果是,按序号排序)
您希望您的数据按时间顺序显示吗?(如果是,按 排序timeStamp

在任何情况下,我都不会使用有序关系作为排序顺序,因为您可能希望 FRC 在表格视图中显示您的数据,他将为您管理内存和更改。
除此之外,您在任何情况下都希望批量获取此关系,而不是简单地让您的表视图数据源成为有序集合关系(这将导致项目被一个接一个地获取)。

于 2013-10-17T17:48:18.763 回答