词典用法和数组排序

NSMutableDictionary *glossary = [NSMutableDictionary dictionary];//创建了一个空的可变词典

NSDictionary *glossary =  [NSDictionary dictionaryWithObjectsAndKeys://不可变词典 以及 快速枚举词典的方式 词典是无序的
                               @"A class",
                               @"Abc",
                               @"B class",
                               @"Bcd",
                               @"C class",
                               @"Cde",nil];
   
for (NSString *key in glossary) {

        NSLog(@"%@%@",key,[glossary objectForKey:key]);


//数组排序

    int i;
   
    propNum = [NSMutableArray arrayWithCapacity:4];
  
    for (i = 0; i <= 4; i++) {
        [propNum addObject:[NSNumber numberWithInteger:[selfRandomNumber: 4to: 24]]];
    }
    NSLog(@"New`````````");
    NSLog(@"排序前%@ %i",propNum,propNum.count);
   
    for (int j = 0; j <=[propNumcount]-1 ; j++){ //多一次for循环变成为由大到小的排序,如果取消本循环则成为最小数在末尾

        for (int j = 0; j <=[propNumcount]-1 ; j++) {
           
            int x = (j == propNum.count - 1) ? propNum.count - 1 : j + 1;
            NSInteger a1 = [[propNumobjectAtIndex:j] intValue];
            NSInteger a2 = [[propNumobjectAtIndex:x] intValue];
            if (a1 < a2)
                [propNum  exchangeObjectAtIndex:j withObjectAtIndex: x];
           
        }
    }
           
   
   
   
    NSLog(@"排序后%@",propNum);
    [propNum removeLastObject];
    returnpropNum;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值