NSSortDescriptor *sortDescriptor;
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"date"
ascending:YES] autorelease];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
self.sortedArray = [self.originalArray sortedArrayUsingDescriptors:sortDescriptors];
これは、日付キーに実際に日付オブジェクトが含まれていて、文字列の形式で日付が含まれている場合に機能するはずです..これを試す必要があります..
[resultArray sortUsingComparator:^NSComparisonResult(id a, id b) {
static NSDateFormatter *dateFormatter = nil;
if (!dateFormatter) {
dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"mm/dd/yyyy hh:mm:ss";
}
NSString *date1String = [a valueForKey:@"StartDate"];
NSString *date2String = [b valueForKey:@"StartDate"];
NSDate *date1 = [dateFormatter dateFromString:date1String];
NSDate *date2 = [dateFormatter dateFromString:date2String];
return [date1 compare:date2];
}];