ios – 警告的原因是什么“指针缺少可空性类型说明符”?

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

这是我班上的方法定义.这引起了警告.什么是类似警告的原因以及如何解决这些问题?

我正在返回一个UIColor对象,而这个问题与块有关,在注释中给出.

所以,这很有帮助.

解决方法

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.

所以,你只是这样做.

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

这在中定义

“NSObjCRuntime.h”

#define NS_ASSUME_NONNULL_BEGIN _Pragma(“clang assume_nonnull begin”) #define NS_ASSUME_NONNULL_END _Pragma(“clang assume_nonnull end”)

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...