字典是无序的
创建字典
- NSMutableDictionary *dic=[NSMutableDictionary dictionary];
- NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:@"张三" forKey:@"name"];
字典添加数据
[dic setObject:@"张小三"forKey:@"sonName"];
[dic setObject:@[@"小明",@"小李",@"小张"] forKey:@"firends"];
从字典中取数据
NSString *name = [dic objectForKey:@"sonName"];
NSArray *firendArr = dic[@"firends"];
遍历字典
NSArray *keys = dic.allKeys;
for (NSString *key in keys) {
NSObject *obj = dic[key];
NSLog(@"字典中装的是:%@",obj);
}
时间: 2024-10-24 08:44:08