標籤:nsdate 基本 singleton get 基本類型 span idg elf code
YYModel源碼中有一句:kCFNull
//解析model屬性並附值+ (instancetype)yy_modelWithDictionary:(NSDictionary *)dictionary { if (!dictionary || dictionary == (id)kCFNull) return nil; if (![dictionary isKindOfClass:[NSDictionary class]]) return nil; Class cls = [self class]; //解析class得到modelmeta對象 _YYModelMeta *modelMeta = [_YYModelMeta metaWithClass:cls]; //本地class類型映射 if (modelMeta->_hasCustomClassFromDictionary) { cls = [cls modelCustomClassForDictionary:dictionary] ?: cls; } NSObject *one = [cls new]; //附值函數 if ([one yy_modelSetWithDictionary:dictionary]) return one; return nil;}
nil: define the id of a null instance, 指向一個(執行個體)對象的null 指標
如:NSString *str = nil;
NSDate *date = nil;
Nil:defines the id of a null class, 指向一個類的null 指標
Class class = Nil;
NULL:定義其他類型(基本類型,C類型)的null 指標
char *p = NILL;
NSNull:數組中元素的預留位置, 資料中的元素不能為nil(可以為空白,也就是NSNull)
原因:nil 是組數的結束標識
如果使用nil,在n個數組中的第k個,那個數組的長度就只有 k 個元素。
kCFNull: NSNull 的單例
CoreFoundation 中有一段對 kCFNull的定義, 實際上就是 NSNull 的單例
typedef const struct CF_BRIDGED_TYPE(NSNull) __CFNull *CFNullRef;
CF_EXPORT
CFTypeID CFNullGetTypeID(void);
CF_EXPORT
const CFNullRef kCFNull;//the singleton null instance
NSNull *null1 = (id)kCFNull;
NSNull *null2 = [NSNull null];
OC,nil,NULL,Nil,kCFNull