关键字nullable、nonnull、null_resetta

2018-08-06  本文已影响8人  Jorunk
好处:

nullable

     方式一:
     @property (nonatomic, strong, nullable) NSString *name;
     方式二:
     @property (nonatomic, strong) NSString * _Nullable name;
     方式三:
     @property (nonatomic, strong) NSString * __nullable name;

nonnull

方式一:
    @property (nonatomic, strong, nonnull) NSString *name;
    方式二:
    @property (nonatomic, strong) NSString * _Nonnull name;
    方式三:
    @property (nonatomic, strong) NSString * __nonnull name;

在NS_ASSUME_NONNULL_BEGIN与NS_ASSUME_NONNULL_END之间所有的对象属性,方法参数,方法返回值,默认都是nonnull。

null_resettable

方式一:
     @property (nonatomic, strong, null_resettable) NSString *name;

注意:用null_resettable属性,必须重写set,或者get方法,处理传值为nil的情况,可以模仿控制器view的get方法,当view为nil,就自己创建一个.

_Null_unspecified

   方式一:
   @property (nonatomic, strong) NSString * _Null_unspecified name;
上一篇下一篇

猜你喜欢

热点阅读