Reputation: 1646
+ (UIColor*) getColorWithHexa(NSString*)hexString;
This is a method definition in my class. It's causing a warning. What is cause of similar warnings and how can these be resolved?
I am returning an UIColor object, while that question relates to blocks, which is given in comments.
So, it's helpful.
Upvotes: 6
Views: 7479
Reputation: 15639
NS_ASSUME_NONNULL_BEGIN/END:
Annotating any pointer in an Objective-C header file causes the compiler to expect annotations for the entire file, bringing on a cascade of warnings. Given that most annotations will be nonnull, a new macro can help streamline the process of annotating existing classes. Simply mark the beginning and end of a section of your header with NS_ASSUME_NONNULL_BEGIN and ..._END, then mark the exceptions.
So,you have simply do.
NS_ASSUME_NONNULL_BEGIN
+ (UIColor*) getColorWithHexaCode:(NSString*)hexString;
NS_ASSUME_NONNULL_END
This is defined in
"NSObjCRuntime.h"
#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
Upvotes: 16
Reputation: 38657
You got this warning when somewhere in the file you used either _Nonnull
, _Nullable
, _Null_unspecified
, __nullable
, __nonnull
, nullable
or nonnull
. Could also happen if the specifier was added through a macro.
To fix the warning:
_Nonnull
using NS_ASSUME_NONNULL_BEGIN
and NS_ASSUME_NONNULL_END
(recommended)Upvotes: 9