码迷,mamicode.com
首页 > 其他好文 > 详细

NSDictionary

时间:2015-10-15 21:52:09      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

// ------------------------------字典-------------------------------------------------

    NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"111", @"one", @"222", @"two", @"333", @"three", nil];

    NSLog(@"dic count=%ld", [dic1 count]);

    for (id key in dic1)

    {

        NSLog(@"key=%@, value=%@", key, [dic1 objectForKey:key]);

    }

    

    // 可变字典

    NSMutableDictionary *dic2 = [NSMutableDictionary dictionaryWithCapacity:1];

    [dic2 setObject:@"111" forKey:@"one"];

    [dic2 setObject:@"222" forKey:@"two"];

    [dic2 setObject:@"333" forKey:@"three"];

    [dic2 setObject:@"444" forKey:@"four"];

    [dic2 setObject:@"555" forKey:@"five"];

    NSLog(@"dic2=%@",dic2);

    [dic2 removeObjectForKey:@"three"];

    NSLog(@"dic2=%@",dic2);

    

    NSLog(@"dic allkeys = %@", [dic2 allKeys]);

    NSLog(@"dic allValues = %@", [dic2 allValues]);

 

NSDictionary

标签:

原文地址:http://www.cnblogs.com/xiangjune/p/4883526.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!