nullable作用:表示可以為空
nullable書寫規(guī)范:
// 方式一:
@property (nonatomic, strong, nullable) NSStringname;
// 方式二:
@property (nonatomic, strong) NSString_Nullable name;
// 方式三:
@property (nonatomic, strong) NSString *__nullable name;
/
//@property (nonatomic, strong) NSString__nullable name;
//@property (nonatomic, strong) NSString * name;
/*
nonnull: non:非 null:空
書寫格式:
@property (nonatomic, strong, nonnull) NSString *icon;
@property (nonatomic, strong) NSString * _Nonnull icon;
@property (nonatomic, strong) NSString * __nonnull icon;
*/
/
在NS_ASSUME_NONNULL_BEGIN和NS_ASSUME_NONNULL_END之間,定義的所有對象屬性和方法默認(rèn)都是nonnull/
// 方法中,關(guān)鍵字書寫規(guī)范
/**
(nonnull NSString)test:(nonnull NSString)str;
(NSString_Nonnull)test1:(NSString_Nonnull)str;
*/
//@property (nonatomic, assign) int age;
/
null_resettable: get:不能返回為空, set可以為空
// 注意;如果使用null_resettable,必須 重寫get方法或者set方法,處理傳遞的值為空的情況
// 書寫方式:
@property (nonatomic, strong, null_resettable) NSStringname;
*/
/
_Null_unspecified:不確定是否為空
書寫方式只有這種
方式一
@property (nonatomic, strong) NSString_Null_unspecified name;
方式二
@property (nonatomic, strong) NSString__null_unspecified name;/
// iOS9新出的關(guān)鍵字:用來修飾屬性,或者方法的參數(shù),方法的返回值
// 好處:
// 1.迎合swift
// 2.提高我們開發(fā)人員開發(fā)規(guī)范,減少程序員之間交流
// 注意:iOS9新出關(guān)鍵字nonnull,nullable只能修飾對象,不能修飾基本數(shù)據(jù)類型
文/我勒個去的(簡書作者)
原文鏈接:http://www.reibang.com/p/f284204f9a98
著作權(quán)歸作者所有贤惯,轉(zhuǎn)載請聯(lián)系作者獲得授權(quán),并標(biāo)注“簡書作者”外潜。