以下代码生成不一致的输出。它应该记录“testString is nil : (null)”。但它有时也会记录“testString is : (null)”。
是什么原因造成的,还是我遗漏了什么?
NSString *testString = nil;
if (!testString)
NSLog(@"testString is nil : %@", testString);
else
NSLog(@"testString is : %@", testString);
最佳答案
您的测试字符串很可能来自,例如,一个 stringWithFormat 操作,例如 stringWithFormat:@"%@", someObject
,而 "someObject"为 nil。
关于objective-c:零检测不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7770423/