zoukankan      html  css  js  c++  java
  • 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];

  • 相关阅读:
    MySQL Create table as / Create table like
    Oracle CAST() 函数 数据类型的转换
    day 12
    day 11
    day 10
    day 9
    day 8
    day 7
    day 6
    day 5
  • 原文地址:https://www.cnblogs.com/wjw-blog/p/9647714.html
Copyright © 2011-2022 走看看