Warning when using nonnull?

With this code:

- (nonnull NSString *)testing { return nil; } 

Should I get a compiler warning? I don't know any warnings that seem to be useless for the whole zero thing?

+5
source share
2 answers

Well, in my opinion, this should trigger a warning, but I could not understand to get it.

Which may be useful using Product > Analyze to run the CLANG Static Analyzer. This should give the following hint:

Null is returned from a method that should return a non-zero value

Another note is the setting CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION , which is called Incorrect Uses of Nullable values in the Apple LLVM 7.1 - Warnings - All languages section in the build settings.

This parameter will not result in a warning about incorrect return values, but when using the method with incorrect parameters, a warning is displayed (for example, nil for abnormal parameters).

This answer applies to Xcode version 7.3.1 (7D1014)

+1
source

"nonnull" is mainly used to combine Objective-C and Swift. Swift will translate the method type to "NSString" rather than "NSString?"

0
source

Source: https://habr.com/ru/post/1245234/


All Articles