在NSArray NSDictionary NSSet等集合對(duì)象中存儲(chǔ)一個(gè)對(duì)象鞠柄,若是該對(duì)象從后臺(tái)獲取時(shí)返回的是nil把兔,則會(huì)出現(xiàn)如下代碼下效果
NSMutableDictionary *params= [NSMutableDictionary dictionary];
[dic setObject:nil forKey:@"name"];
這樣會(huì)出現(xiàn)Crash丐怯,因?yàn)閚il無(wú)法存儲(chǔ)一個(gè)空值户辞。
而對(duì)NSArray來(lái)說(shuō)僵闯,nil表示這個(gè)字典對(duì)象的元素截止了卧抗,即NSArray只會(huì)關(guān)注nil之前的對(duì)象,nil之后的對(duì)象會(huì)被忽略鳖粟,比如:
NSArray *arr = [NSArray arrayWithObject:@"name",@"password",@"phoneNum",nil];
要想存儲(chǔ)一個(gè)空值社裆,可用[NSNull null]空對(duì)象來(lái)存儲(chǔ)。如下:
[param setObject:[NSNull null] forKey:@"name"];
NSArray *arr = [NSArray arrayWithObject:@"name",@"password",@"phoneNum",[NSNull null],nil];