OC,nil,NULL,Nil,kCFNull

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.