简体   繁体   English

如何对两个不同的核心数据对象进行排序?

[英]How to sort two different core data objects?

I have two core data entities. 我有两个核心数据实体。 Say Birthday & Anniversary . 生日周年纪念日

Attributes of these entities are, 这些实体的属性是

Birthday - Name, Age, Birth date 生日 -姓名,年龄,出生日期

Anniversary - Name, Anniversary date 周年纪念 -名称,周年纪念日

Showing each entity separately in a tableview can be done with fetched results controller. 可以使用获取的结果控制器在表格视图中单独显示每个实体。 Thats fine!! 没关系!! But, I want to show a tableview that combines both birthdays and anniversary days. 但是,我想显示一个结合了生日和周年纪念日的表格视图。 The sorting should be done by taking "Birth date" from Birthday & "Anniversary date" from Anniversary entity. 排序应采用生日实体的“ 生日 ”和周年实体的“周年纪念日”。

Questions : 问题

  • Should I use two fetchedresultscontroller to fetch objects from these two entities? 是否应该使用两个fetchedresultscontroller控制器从这两个实体中获取对象? And then should I sort those objects? 然后我应该对那些对象进行排序? This is fine with minimal objects, but it takes more processing time when the count increases. 使用最少的对象就可以了,但是当计数增加时,则需要更多的处理时间。

  • Should I create a common parent table, that posses "Birth date" and "Anniversary date" values? 我是否应该创建一个具有“出生日期”和“周年日期”值的公共父表? If so, how can I fetch & how can I define sort descriptor? 如果是这样,我如何获取和如何定义排序描述符?

I'm really new to core data and dont have any idea about this scenario. 我对核心数据真的很陌生,对这种情况一无所知。 Giving examples would be appreciated. 提供示例将不胜感激。

Thanks 谢谢

You're best bet might be to use two fetchedresultscontrollers , then sort each set of results within each other, then merge the two. 最好的选择是使用两个fetchedresultscontrollers ,然后将每个结果集相互排序,然后将两者合并。 That seems like a logical way to accomplish this...Another idea might be to have a common model between Birthday and Anniversary that shares as many properties as possible (IE name and date), and then you're sort descriptor could work on the model super class' date property. 这似乎是完成此任务的一种逻辑方法...另一个想法可能是在生日和周年纪念日之间建立一个通用模型,该模型共享尽可能多的属性(例如,IE名称和日期),然后您可以对描述符进行排序模型超类的日期属性。

Add a parent entity. 添加父实体。 Both anniversary and birthday should inherit common properties. 周年纪念日和生日应该继承共同的属性。 Then You can use one frc to query both anniversary and birthday. 然后,您可以使用一个frc来查询周年纪念日和生日。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM