按对象的NSDate属性对数组进行排序 [英] Sort array of objects by their NSDate property
本文介绍了按对象的NSDate属性对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
How to sort an NSMutableArray with custom objects in it?
如何通过访问对象的NSDate属性对数组进行排序?
How does one sort an array of objects by accessing their NSDate properties?
我知道一个人可以在日期数组上使用[mutableArray sortUsingSelector:@selector(compare:)];
,但是如何通过访问数组中每个元素的NSDate属性并按最早日期到最新日期对对象进行排序呢?
I know one can use [mutableArray sortUsingSelector:@selector(compare:)];
on an array of dates, but how does one do it by accessing a NSDate property on each element in the array, sorting the objects by earliest date to latest date?
推荐答案
Thanks for all the answers, I came across this answer that solved my problem.Check NSGod's answer
以下是感谢用户NSGod的代码:
Here is the code thanks to user: NSGod:
NSSortDescriptor *dateDescriptor = [NSSortDescriptor
sortDescriptorWithKey:@"startDateTime"
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
NSArray *sortedEventArray = [nodeEventArray
sortedArrayUsingDescriptors:sortDescriptors];
这篇关于按对象的NSDate属性对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文