根据日期对NSDictionary数组进行排序

Da4*_*a49 -2 cocoa-touch objective-c nsdictionary nsdate nsarray

我正在寻找一种NSMutableArray基于字典中包含的日期对字典进行排序的方法.每个人看起来像这样:

{
  name: tom, 
  surname: smith, 
  date of birth (NSDate): 2013-02-21 15:25:27
}
Run Code Online (Sandbox Code Playgroud)

我知道方法earlierDate等,但因为他们只比较两个日期我只是有点卡在如何迭代数组,以便我出来一个完全有序的字典数组?

Jon*_*hon 5

使用sortUsingComparator它可以很容易地解决:

[yourArray sortUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {
   return [a[@"dateOfBirth"] compare:b[@"dateOfBirth"]];
}];
Run Code Online (Sandbox Code Playgroud)