OC,nil,NULL,Nil,kCFNull

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, 指向一个(实例)对象的空指针

如:NSString *str = nil;

  NSDate *date = nil;

Nil:defines the id of a null class, 指向一个类的空指针

  Class class = Nil;

NULL:定义其他类型(基本类型,C类型)的空指针

  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];

猜你喜欢

转载自www.cnblogs.com/wjw-blog/p/9647714.html