- (NSArray *)sortedArrayUsingFunction
:(NSInteger (*)(id, id, void *))comparator context:(void *)context;
给一个数组调用该方法[array
sortedArrayUsingFunction
:sort];
NSInteger sort(id a,id b,void context){
//取a,b中的值进行比较
}
//排序比较
NSInteger sort(NSDictionary *dic1,NSDictionary *dic2,void *context) {
double key1 = [[dic1 objectForKey:@"key"] doubleValue];
double key2 = [[dic2 objectForKey:@"key"] doubleValue];
if (key1 > key2 ) {
//key1小于key2
return NSOrderedDescending;
}else if (key1 == key2) {
//相同
return NSOrderedSame;
}else {
return NSOrderedAscending;
}
}
给一个数组调用该方法[array
NSInteger sort(id a,id b,void context){
//取a,b中的值进行比较
}
//排序比较
NSInteger sort(NSDictionary *dic1,NSDictionary *dic2,void *context) {
//key1小于key2
//相同
}