字典的相关操作

来源:互联网 发布:超市扫码枪软件费用 编辑:程序博客网 时间:2024/05/20 11:37

     

        NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:@"one",@"1",@"two",@"2",@"three",@"3",nil];

       NSLog(@"1---%@",dict);

        

       // 字典的遍历

       NSEnumerator *enumerator = [dict objectEnumerator];

       id obj ;

       while (obj = [enumerator nextObject]) {

           NSLog(@"2----%@",obj);

        }

        

       NSString *str = [dict objectForKey:@"2"];

       NSLog(@"3----%@",str);

        

       for (id objin dict) {

           NSLog(@"4-----%@",obj);

        }

        

        /* 可变字典*/

        NSMutableDictionary *mudict = [[NSMutableDictionaryalloc]init];

        [mudictsetObject:@"one"forKey:@"1"];

        [mudictsetObject:@"two"forKey:@"2"];

        [mudictsetObject:@"three"forKey:@"3"];

        NSLog(@"5---%@",mudict);

        [mudictremoveObjectForKey:@"2"];

        NSLog(@"6---%@",mudict);

0 0
原创粉丝点击