转载自:
有这样一段代码:
NSDictionary* items2=[NSDictionary dictionaryWithObjectsAndKeys:
[d objectForKey:@"GZDBH"],@"工作单编号",
[d objectForKey:@"LDSJ"],@"来电时间",
[d objectForKey:@"SLWCSJ"],@"受理完成时间",
[d objectForKey:@"SLR"],@"受理人",
[d objectForKey:@"ZJHM"],@"主叫号码",
[d objectForKey:@"LXR"],@"联系人",
[d objectForKey:@"LXDH"],@"联系电话",
[d objectForKey:@"BXDZ"],@"报修地址",
[d objectForKey:@"CLLX"],@"故障类型",
[d objectForKey:@"JRLX"],@"接入类型",
[d objectForKey:@"CLQY"],@"处理区域",
[d objectForKey:@"FWJB"],@"服务级别",
[d objectForKey:@"JJCD"],@"紧急程度",
[d objectForKey:@"YXFW"],@"影响范围",
[d objectForKey:@"QKMS"],@"受理情况",
nil];
但是后来发现items2中始终只有一个对象“工作单编号“,检查后发现,其中“来电时间”对象是空,而dictionaryWithObjectsAndKeys方法在遇到nil对象时,会以为是最终的结束标志。于是items中只放了一个对象就初始化结束了,而且不管编译和运行中都不会报错,这样的bug显然很隐蔽。