Sort NSArray of custom objects by their NSDate properties

后端 未结 5 1255
执笔经年
执笔经年 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:47

    You can achieve like this,

    NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"anyDateField"  ascending:YES];
    
    NSMutableArray *arr = [[array sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]mutableCopy];
    

提交回复
热议问题