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

OC -- NSDictionary NSMutableDictionary

时间:2015-07-15 20:58:33      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

NSDictionary  NSMutableDictionary 只能存放OC对象,不能存放int, float, double, struct, enum类型数据

NSDictionary *dict1 = @{@"name" : @"As god name", @"address" : @"shanghai", @"program" : @"ios"};

NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"name" : @"xingxing", @"address" : @"universe", @"program" : @"unix", nil];  // 不常用

NSMutableDictionary *dict3 = @{@"name" : @"cnblog", @"address" : @"Internet", @"program" : @"ios"};

NSMutableDictionary *dict4 = [NSDictionary dictionaryWithObjectsAndKeys:@"name" : @"hero", @"address" : @"china", @"program" : @"oc", nil];  // 不常用

[dict3 setObject:@"like" forKey:@"run"];  // 添加键值对

[dict3 removeObjectForKey:@"program"];  // 删除键值对

NSUInteger *count = dict3.count;  // 取出dict3中键值对的总数

NSString *str1 = dict3[@"name"];

NSDictionary  NSMutableDictionary 的遍历

[dict3 enumerateKeysAndObjectsUsingBlock:

^(id key, id obj, BOOL *stop){

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

}

];

 

OC -- NSDictionary NSMutableDictionary

标签:

原文地址:http://www.cnblogs.com/lianfu/p/4649375.html

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