蘋果為什么要推出關(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;