iOS9新特性之关键字

nonnull

nullable

NSSet<UITouch *>

01-iOS9新特性之关键字

  • iOS9新出的关键字:用来修饰属性,或者方法的参数,方法的返回值

  • 好处:

    • 提高我们开发人员开发规范,减少程序员之间交流
  • 注意:

    • iOS9新出关键字nonnull,nullable,null_resettable,_Null_unspecified只能修饰对象,不能修饰基本数据类型.
  • nullable作用:表示可以为空

 nullable书写规范:
 // 方式一:
 @property (nonatomic, strong, nullable) NSString *name;
 // 方式二:
 @property (nonatomic, strong) NSString *_Nullable name;
 // 方式三:
 @property (nonatomic, strong) NSString *__nullable name;
  • nonnull作用:不能为空
nonnull: non:非 null:空

书写格式:
 @property (nonatomic, strong, nonnull) NSString *icon;

 @property (nonatomic, strong) NSString * _Nonnull icon;

 @property (nonatomic, strong) NSString * __nonnull icon;


  • NS_ASSUME_NONNULL_BEGINNS_ASSUME_NONNULL_END之间,定义的所有对象属性和方法默认都是nonnull

  • null_resettable作用: get:不能返回为空, set可以为空

// 书写方式:
@property (nonatomic, strong, null_resettable) NSString *name;

 // 注意;如果使用null_resettable,必须 重写get方法或者set方法,处理传递的值为空的情况


  • _Null_unspecified:不确定是否为空
书写方式只有这种
    方式一
    @property (nonatomic, strong) NSString *_Null_unspecified name;
    方式二
    @property (nonatomic, strong) NSString *__null_unspecified name;

转载于:https://my.oschina.net/KeepDoing/blog/1058155

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值