Sort NSArray of custom objects by their NSDate properties

后端 未结 5 1276
执笔经年
执笔经年 2020-11-30 06:20

I am attempting to sort an NSArray that is populated with custom objects. Each object has a property startDateTime that is of type NSDate.

The followin

5条回答
  •  甜味超标
    2020-11-30 06:46

    Did you try by specifying the NSDate comparator?

    Eg:

    NSSortDescriptor *dateDescriptor = [NSSortDescriptor
       sortDescriptorWithKey:@"startDateTime"
       ascending:YES
       selector:@selector(compare:)];
    

    This should enforce the usage of the correct comparator of the NSDate class.

提交回复
热议问题