像这样的代码:
- (nonnull NSString *)testing {
return nil;
}
我不应该收到编译器警告吗?我没有得到任何警告,这似乎让整个可空性看起来毫无用处?
最佳答案
好吧,在我看来它应该产生警告,但我也想不出要发出警告。
不过,使用 Product > Analyze
运行 CLANG 静态分析器可能会有帮助。这应该给出以下提示:
Null is returned from a method that is expected to return a non-null value
另一件值得一提的事情是 CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION
设置,它在 Apple LLVM 7.1 - Warnings - All languages
中被命名为 Incorrect Uses of Nullable values
build设置部分。
此设置不会对不正确的返回值产生警告,但会在使用具有不正确参数的方法时显示警告(例如,对于非空参数为 nil)。
此答案引用 Xcode Version 7.3.1 (7D1014)
关于objective-c - 使用nonnull时没有警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36062487/