objective-c:零检测不一致

标签 objective-c ios

以下代码生成不一致的输出。它应该记录“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/

相关文章:

objective-c - 枚举 Objective-C 和 Swift 之间的互操作性

ios - 添加完成/旁边到数字键盘

ios - 如何在 UITextView 中像 block 引号一样格式化文本

ios - 使用 SIGPIPE 停止的网络代码

ios - 运行命令时遇到内部错误 : Error: Unable to launch WebDriverAgent because of xcodebuild failure: "xcodebuild failed with code 70"

ios - SKSpriteNode 仅在 iOS 9 或更高版本上可见,无论是在模拟器还是在真实手机中?

ios - 从左侧和右侧对齐具有 "\n"的标签

iOS可变数组始终为空

ios - 从 Objective C 中的 Swift 类继承

ios - 滚动时 TableView UILabel 对齐方式发生变化