zoukankan      html  css  js  c++  java
  • iOS

    方法一:
        NSArray *sortArray = [arrayM sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
                    SDHomeNewTaskModel *model1 = obj1;
                    SDHomeNewTaskModel *model2 = obj2;
                    if ([model1.distance floatValue] > [model2.distance floatValue]) {
                        return NSOrderedDescending;//降序
                    }else if ([model1.distance floatValue] > [model2.distance floatValue]){
                        return NSOrderedAscending;//升序
                    }else {
                        return NSOrderedSame;//相等
                    }
                }];
                for (SDHomeNewTaskModel *model in sortArray) {
                    NSLog(@"distance3:------> %@", model.distance);
                }
    方法二:
                    NSMutableArray *arr = [NSMutableArray array];
                for (int i =0; i < arrayM.count; i ++) {
                    SDHomeNewTaskModel *model = arrayM[i];
                    [arr addObject:model];
                    NSLog(@"distance2:------> %@", model.distance);
                }
                //这里类似KVO的读取属性的方法,直接从字符串读取对象属性,注意不要写错ascending:指定一个集合是否按照升序(YES)还是降序(NO)
                NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES];
                //这个数组保存的是排序好的对象
                NSArray *arr = arrayM;
                NSArray *tempArray = [arr sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
                // 输出排序结果
                for (SDHomeNewTaskModel *model in tempArray) {
                    NSLog(@"distance3:------> %@", model.distance);
                }
    方法三:
        -(NSString*)stringWithDict:(NSDictionary*)dict {
        NSArray*keys = [dict allKeys];
        NSArray*sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) {
            return [obj1 compare:obj2 options:NSNumericSearch];
        }];
        NSString *str = @"";
        for(NSString*categoryId in sortedArray) {
            id value = [dict objectForKey:categoryId];
            if([value isKindOfClass:[NSDictionary class]]) {
                value = [self stringWithDict:value];
                
            }
        NSLog(@"[dict objectForKey:categoryId] === %@",[dict objectForKey:categoryId]);
            if([str length] !=0) {
                str = [str stringByAppendingString:@";"];
                
            }
            str = [str stringByAppendingFormat:@"%@:%@",categoryId,value];
            
        }
        return str;
        
    }
    方法四:
        
    -(NSString *)getNeedSignStrFrom:(id)obj{
        NSDictionary *dict = obj;

        NSArray *arrPrimary = [dict.allKeys mutableCopy];

        
        NSArray *arrKey = [arrPrimary sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
            NSComparisonResult result = [obj1 compare:obj2];
            return result==NSOrderedDescending;//NSOrderedAscending 倒序
        }];
        
        NSString*str =@"";
        
        for (NSString *s in arrKey) {
            id value = dict[s];
            if([value isKindOfClass:[NSDictionary class]]) {
                value = [self getNeedSignStrFrom:value];
            }
            if([str length] !=0) {
                
                str = [str stringByAppendingString:@","];
                
            }
            
            str = [str stringByAppendingFormat:@"%@:%@",s,value];
            
        }
        NSLog(@"str:%@",str);
        
        return str;
    }
  • 相关阅读:
    AX 2012 Form and Parts
    AX 2012 SSRS print setting-报表打印输出设置
    AX 2012 关于parts 添加
    AX Dynamic 2012 tabletype:TempDB使用
    AX Dynamic 2012 SSRS 按行数分页
    AX Dynamic 2012 SSRS autorepot中取当前公司名、打印时间、打印页码
    AX Dynamics 去中文字符长度:中文字符当2个字符处理
    AX dynamics 2012 ssrs 开发报错:Native compiler return value: ‘[BC30179]
    在Ubuntu 下编译c语言
    在ubuntu加载flash的方法
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10649998.html
Copyright © 2011-2022 走看看