nullable,
nonnull,
null_resettable,
_Null_unspecified等使用来修饰属性,或者方法的参数,返回值。
好处是:1、迎合swift的特性;2、更加规范开发人员,同时减少程序员之间的沟通成本
nullable
作用:表示可以为空
特点:只能修饰对象,不能修饰基本数据类型
1、修饰成员变量
@property (nonatomic, strong, nullable) NSString *name;
@property (nonatomic, strong) NSString *_Nullable name;
@property (nonatomic, strong) NSString *__nullable name;
2、修饰方法的返回值或参数
- (NSString * _Nullable)test:(NSString * _Nullable)str;
nonnull
作用:标识非空
特点:只能修饰对象,不能修饰基本数据类型
1、修饰成员变量
2、修饰方法的返回值或参数
_Null_unspecified
作用:不确定是否为空
书写规范:
null_resettable
作用:处理set方法传递空值得情况,使用了这个属性修饰成员变量,get方法不能返回空,setter方法可以为空
特点:使用null_resettable修饰成员变量,必须重写get方法或者set方法,处理传递值为空的情况
书写规范: