iOS9新特性之常见关键字

2016-03-26  本文已影响0人  gzliq

苹果为什么要推出关键字?

迎合swift,swift强语言,OC弱语言,swift必须描述属性有没有值

关键字注意点: 

1.只对方法起作用,对属性不起作用

2.仅仅是报警告,并不是报编译错误

3.关键字不能描述基本数据类型,只能用于描述对象类型

常见关键字好处:

1.提示开发人员这个书写特性,减少程序员之间交流,提高代码规范

beta版本:苹果每推出一个新的xcode之前,都会出beta,

1.让开发人员先熟悉新API

2.不能使用beta版本创建项目 

3.不能使用beta版本上传App Store

nullable:可能为空

书写格式:

方式一:

@property (nonatomic ,strong , nullable) NSString *name;

方式二:

@property (nonatomic ,strong) NSString * _Nullable name;

方式三:beta

@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;

null_resettable:get不能为空.set方法可以为空

开发中如何使用:

null_resettable注意:一定要处理为nil的情况,重写属性get方法

书写格式:

@property (nonatomic ,strong, null_resettable) NSString *name;

_Null_unspecified:不确定是否为空

上一篇 下一篇

猜你喜欢

热点阅读