有没有办法在将值分配给 BOOL 之前检查该值是否为 NULL/Nil?
例如,我在 NSDictionary 中有一个值可以是 TRUE/FALSE/NULL
mySTUser.current_user_following = [[results objectForKey:@"current_user_following"]boolValue];
当值为 NULL 时,出现以下错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSNull boolValue]: unrecognized selector sent to instance
我希望能够处理 NULL 情况。
你应该检查 http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/NumbersandValues/Articles/Null.html [NSNull null]
:
id vUser = [results objectForKey:@"current_user_following"];
if (vUser != [NSNull null]) {
// do stuff...
}
else {
// handle the case appropriately...
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)