NSString *str = nil;
NSDictionary *dic = @{@"key":str};
//zs20171220 会崩溃'*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]
字面量添加nil 会崩溃
NSString *str = nil;
NSDictionary *dicParam = [[NSDictionary alloc] initWithObjectsAndKeys:@"",@"key1",str,@"key2",nil];
NSLog(@"dicParam____%@",dicParam[@"key2"]);//zs20171220 value 值可以为nil,但是这个时候nil意味着结束添加了
NSLog(@"dicParam____%@",dicParam.allKeys); NSLog(@"dicParam____%@",dicParam[@"key1"]);//zs20171220 key 不能设置成nil 否则会崩溃
NSString *str = nil;
NSMutableDictionary *dicMutable = [NSMutableDictionary dictionaryWithCapacity:0];
[dicMutable setValue:str forKey:@"key1"];//zs20171220 插入nil 不会崩溃
[dicMutable setValue:@"ddd" forKey:@"key2"];
[dicMutable setValue:nil forKey:@"key3"];//zs20171220 插入nil 不会有这个key 和值
NSLog(@"___%@",dicMutable);
网友评论