程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Dictionary and Array value cannot be nil

Dictionary and Array value cannot be nil

編輯:C++入門知識

Dictionary and Array value cannot be nil


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);


}



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved