蘋果為什么要推出關鍵字?
迎合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;