iphone - 按 NSDate 对字典数组进行排序

标签 iphone objective-c ios xcode

我有一系列字典。在每个字典中,有一个键 dateOfInfo(一个 NSDate)和其他一些东西。我想按每个字典 dateOfInfo 对数组进行排序,最新的是第一个结果。

我该怎么做?

最佳答案

您可以使用 NSSortDescription 进行排序,例如

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey: @"dateOfInfo" ascending: NO];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];

也可以使用方法

- (NSArray *)sortedArrayUsingFunction:(NSInteger (*)(id, id, void *))comparator context:(void *)context

关于iphone - 按 NSDate 对字典数组进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7507457/

上一篇:IOS:.png 的动画

下一篇:IOS方法调用

相关文章:

iphone - 你如何给自己做一个segue?

iphone - iOS 4.2 相机和相册问题

iphone - 缩放 Chrome/Safari 时 CSS 水平菜单中断

objective-c - 如何在 iPhone 中执行延迟测试

iphone - iOS:如何查询nsmutablearray对象中的对象

iphone - XCode 4 无法在设备上运行可执行文件

ios - 关于 UIScrollView 作为启用 UIPanGesture 的 View 的 subview 的问题

iphone - iOS 5 iPhone 4 Interface Builder 突然间我的所有 View 都变得透明了。怎么修?

ios - 通过导入的数据库swift进行SQL查询

ios - 如何在UITableView的UiLabel中单击特定位置?