题主你好,
看例子吧:
我先定义一个空字典dic:
dic = {}
向字典中添加键值对是通过:
字典名['键名'] = '值'
这种形式, 下面我向字典中添加一个键为'name', 值为'hello kitty'的这么一个键值对:
dic['name'] = 'hello kitty'
此时字典dic的值就内{}, 变为了{'name': 'hello kitty'}
---
测试截图:
希望可以帮到题主, 欢迎追问
NSDictionary*dic =@{@"8":@"AAAA",
@"2":@"BBBBB",
@"3":@"CCCCCC",
@"1":@"FFFFF"}
NSArray*arrKeys = [dicallKeys]
for ( int i =0i <arrKeys.counti++)
{
NSString*key = arrKeys[i]
NSString*value = [dicvalueForKey:key]
NSLog(@"%@ = %@",key,value)
}
NSLog(@"%zd",dic.count)
// 2
[dicenumerateKeysAndObjectsUsingBlock:^( id key, id obj, BOOL *stop) {
NSLog(@"key = %@ and obj = %@", key, obj)
}]
将一个字典键值添加到另外一个字典中 关键字 setVlue
NSDictionary*dict=@{@"1":@"1",@"2":@"2"}
NSMutableDictionary*myHeader=[[NSMutableDictionaryalloc]init]
[myHeader setValue:@"8"forKey:@"8"]
[myHeader setValue:@"9"forKey:@"9"]
[myHeader setValue:@"10"forKey:@"10"]
[myHeader addEntriesFromDictionary:dict]
可以将 dict 字典的键值对添加到 myHeader 中
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)