现在的位置: 首页 > 综合 > 正文

Dictionary and Array value cannot be nil

2018年08月06日 ⁄ 综合 ⁄ 共 979字 ⁄ 字号 评论关闭
Dictionary value cannot be nil
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[2]'
*** First throw call stack:
 NSString *a;
  dic2 =
@{
            
@"key":@"value",
             
@"ko":@"",
            
@"xue":a
            
}
;

 Array element cannot be nil
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'

*** First throw call stack:
 NSString *a;
 array2 = @[@"",@"0",a];


测试:数组不能有nil的对象,字典不能插入nil的值
-(void)setData{
   
   
NSDictionary *dic1;
   
NSArray *array1;
    dic1 =
@{};
    array1 =
@[];
   
NSLog(@"dic1:%@",dic1);
   
NSLog(@"array1:%@",array1);
   
   
NSDictionary *dic2;
   
NSArray *array2;
   
NSString *a;
//    a=nil;
    dic2 =
@{
            
@"key":@"value",
             
@"ko":@"",
            
@"xue":a
            
};
    array2 =
@[@"",@"0",a];
   
NSLog(@"dic2:%@",dic2);
   
NSLog(@"array2:%@",array2);

}





抱歉!评论已关闭.