iOS9新特性之常見關(guān)鍵字

蘋果為什么要推出關(guān)鍵字?

迎合swift,swift強(qiáng)語(yǔ)言,OC弱語(yǔ)言,swift必須描述屬性有沒(méi)有值

關(guān)鍵字注意點(diǎn):?

1.只對(duì)方法起作用,對(duì)屬性不起作用

2.僅僅是報(bào)警告,并不是報(bào)編譯錯(cuò)誤

3.關(guān)鍵字不能描述基本數(shù)據(jù)類型,只能用于描述對(duì)象類型

常見關(guān)鍵字好處:

1.提示開發(fā)人員這個(gè)書寫特性,減少程序員之間交流,提高代碼規(guī)范

beta版本:蘋果每推出一個(gè)新的xcode之前,都會(huì)出beta,

1.讓開發(fā)人員先熟悉新API

2.不能使用beta版本創(chuàng)建項(xiàng)目?

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方法可以為空

開發(fā)中如何使用:

null_resettable注意:一定要處理為nil的情況,重寫屬性get方法

書寫格式:

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

_Null_unspecified:不確定是否為空

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容