您可以使用该sortUsingComparator:
方法,如下所示:
[array sortUsingComparator: ^(id lhs, id rhs) {
// Get the string between the first and the second semicolons:
NSString *obj1 = [[lhs componentsSeparatedByString:@";"] objectAtIndex:1];
NSString *obj2 = [[rhs componentsSeparatedByString:@";"] objectAtIndex:1];
// Compare the two strings as integers:
if ([obj1 integerValue] > [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedDescending;
}
if ([obj1 integerValue] < [obj2 integerValue]) {
return (NSComparisonResult)NSOrderedAscending;
}
return (NSComparisonResult)NSOrderedSame;
}];