iOS9 新特性 常见关键字

nullable,

nonnull,

null_resettable,

_Null_unspecified等使用来修饰属性,或者方法的参数,返回值。

好处是:1、迎合swift的特性;2、更加规范开发人员,同时减少程序员之间的沟通成本


nullable

作用:表示可以为空

特点:只能修饰对象,不能修饰基本数据类型


1、修饰成员变量


@property (nonatomicstrong, nullable) NSString *name;

@property (nonatomicstrongNSString *_Nullable name; 

@property (nonatomicstrongNSString *__nullable name;


2、修饰方法的返回值或参数


- (NSString * _Nullable)test:(NSString * _Nullable)str;

nonnull

作用:标识非空

特点:只能修饰对象,不能修饰基本数据类型


1、修饰成员变量

[objc]  view plain  copy
  1. // 方式一  
  2. @property (nonatomicstrong, nonnull) NSString *icon;  
  3.  // 方式二  
  4.  @property (nonatomicstrongNSString * _Nonnull icon;  
  5.  // 方式三  
  6.  @property (nonatomicstrongNSString * __nonnull icon;</span>  
2、修饰方法的返回值或参数

[objc]  view plain  copy
  1. - (nonnull NSString *)test:(nonnull NSString *)str;  
  2. - (NSString * _Nonnull)test1:(NSString * _Nonnull)str;</span>  



_Null_unspecified

作用:不确定是否为空

书写规范:

[objc]  view plain  copy
  1.   // 方式一  
  2.     @property (nonatomicstrongNSString *_Null_unspecified name;  
  3.     // 方式二  
  4.     @property (nonatomicstrongNSString *__null_unspecified name;  
  5.  


null_resettable

作用:处理set方法传递空值得情况,使用了这个属性修饰成员变量,get方法不能返回空,setter方法可以为空

特点:使用null_resettable修饰成员变量,必须重写get方法或者set方法,处理传递值为空的情况

书写规范:

[objc]  view plain  copy
  1. @property (nonatomicstrong, null_resettable) NSString *name; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值