根据日期

时间:2018-06-15 05:59:47

标签: ios objective-c realm nspredicate

几个星期前,我被这个问题困扰了。假设您有以下结构:

@interface SomeObject : RLMObject
@property (nonatomic, strong, readwrite) NSDate *someDate;
@end

RLMArray<SomeObject *> *array = ... // Assume that this array is filled with a bunch of objects

是否可以将数组转换为以下结构?

NSDictionary *desiredDict = @{
@"5": // The month of someDate
@[[SomeObject ...]], // An array of objects that have that month
...}

字典中的键代表someDate的月份?

目的:

假设您正在使用后端返回包含日期的未排序对象数组,如何将它们转换为字典,而字典中的键对应于对象的月份?

我想你可以编写一个算法来处理这个问题,然而,看看是否有人有任何其他想法会很有趣。也许是利用NSPredicate的?

0 个答案:

没有答案
相关问题