Changing the sort order of -[NSArray sortedArrayUsingComparator:]
问题 I need to generate a sorted array of NSNumber s from another NSArray . I want to use the sortedArrayUsingComparator: method. I found this example in the Apple documentation: NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerValue] > [obj2 integerValue]) { return (NSComparisonResult)NSOrderedDescending; } if ([obj1 integerValue] < [obj2 integerValue]) { return (NSComparisonResult)NSOrderedAscending; } return (NSComparisonResult)NSOrderedSame; }];