What is the reason for the warning "The pointer does not have a nullability type specifier"?

+ (UIColor*) getColorWithHexa(NSString*)hexString; 

enter image description here :

This is a method definition in my class. This triggers a warning. What causes such warnings and how can they be resolved?

I am returning a UIColor object, while this question relates to blocks, which is indicated in the comments.

So this is helpful.

+7
ios objective-c-nullability
source share
2 answers

NS_ASSUME_NONNULL_BEGIN / END:

Annotating any pointer in the Objective-C header file causes the compiler to expect comments for the entire file, a cascade of warnings. Given that most annotations will be unnecessary, a new macro can help streamline the process of annotating existing classes. Just mark the beginning and end of the section of your heading with NS_ASSUME_NONNULL_BEGIN and ..._ END, then note the exceptions.

So you just did.

 NS_ASSUME_NONNULL_BEGIN + (UIColor*) getColorWithHexaCode:(NSString*)hexString; NS_ASSUME_NONNULL_END 

It is defined in

"NSObjCRuntime.h"

define NS_ASSUME_NONNULL_BEGIN _Pragma ("clang guess_nonnull begin")

define NS_ASSUME_NONNULL_END _Pragma ("clang guess_nonnull end")

thanks

Happy coding.

+13
source share

You received this warning when somewhere in the file you used _Nonnull , _Nullable , _Null_unspecified , __nullable , __nonnull , nullable or nonnull . It can also happen if the specifier was added through a macro.

To fix a warning:

  • you can remove all nullability occurrences (not recommended)
  • you can assume that all parameters and _Nonnull return values _Nonnull used by NS_ASSUME_NONNULL_BEGIN and NS_ASSUME_NONNULL_END (recommended)
+7
source share

All Articles