常见关键字使用

nullable:
作用:可能为空,提示属性可能为空,为了迎合swift(强语言)
好处:提高代码规范,减少沟通成本
用法:可用于修饰属性,参数和返回值
语法:@property(nonatomic,strong,nullable) NSString *name
语法2:@property(nonatomic,strong) NSString * _Nullable name
语法2:@property(nonatomic,strong) NSString * __nullable name

nonnull:
作用:提示不能为空,仅仅是提供警告,并不会报错
语法:同上

null_resetable:
作用:get方法返回值不能为空,set方法可以传入为空
用法:必须要处理为空的情况
语法:@property(nonatomic,strong,null_resettable) NSString *name

关键字不能用于基本数据类型

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章