Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
xCode 的“构建和分析”抱怨“s”可能是垃圾。
哪个是更好的解决方案?A、B 还是 C?
NSString *s; // A NSString *s = nil; // B NSString *s = @""; // C if(x == 1) s = @"you picked 1"; if(x == 2) s = @"you picked 2"; if(x == 3) s = @"you picked 3";
我总是和
NSString *s = nil;
作为默认初始化值。它比空字符串更明智(空字符串是“事物”,而是nil未知值),并且由于您可以nil在 Objective-C 中发送消息,因此(通常)如果我以某种方式忘记提供它不会造成大问题一个“真实”的价值。
nil