标签:
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