美文网首页
iOS 对像

iOS 对像

作者: UILabelkell | 来源:发表于2020-04-09 21:52 被阅读0次

    1、对像

    -概念:是提我们通常类的实例化对像。

    Obj *ob = [Obj new] , ob这也就是一个实例对像
    

    -元类:就是类对像的 isa指像的类

    打开#import <objc/objc.h>这个文件可以看到class与object在Objective-C的定义

    /// An opaque type that represents an Objective-C class.
    typedef struct objc_class *Class;
    
    /// Represents an instance of a class.
    struct objc_object {
        Class _Nonnull isa  OBJC_ISA_AVAILABILITY;
    };
    
    /// A pointer to an instance of a class.
    typedef struct objc_object *id;
    

    这里面class 父类objc_object 是一个结构体类型的指针

    我们在进入objc_object这个类里面,可以看到它详情的体现,可以看到类对像包含的内容

    struct objc_class {
        Class _Nonnull isa  OBJC_ISA_AVAILABILITY;
    
    #if !__OBJC2__
        Class _Nullable super_class                              OBJC2_UNAVAILABLE;
        const char * _Nonnull name                               OBJC2_UNAVAILABLE;
        long version                                             OBJC2_UNAVAILABLE;
        long info                                                OBJC2_UNAVAILABLE;
        long instance_size                                       OBJC2_UNAVAILABLE;
        struct objc_ivar_list * _Nullable ivars                  OBJC2_UNAVAILABLE;
        struct objc_method_list * _Nullable * _Nullable methodLists                    OBJC2_UNAVAILABLE;
        struct objc_cache * _Nonnull cache                       OBJC2_UNAVAILABLE;
        struct objc_protocol_list * _Nullable protocols          OBJC2_UNAVAILABLE;
    #endif
    
    } OBJC2_UNAVAILABLE;
    

    相关文章

      网友评论

          本文标题:iOS 对像

          本文链接:https://www.haomeiwen.com/subject/btahmhtx.html