美文网首页
Class, Method,SEL, IMP

Class, Method,SEL, IMP

作者: 乐天派大星晴 | 来源:发表于2019-04-24 17:01 被阅读0次

    Class:

    定义在 objc.h:

    /// An opaque type that represents an Objective-C class.
    typedef struct objc_class *Class;
    

    objc_class定义在runtime.h

        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;
    

    Method

    Method 定义在 runtime.h:

    struct objc_method {
        SEL _Nonnull method_name                                 OBJC2_UNAVAILABLE;
        char * _Nullable method_types                            OBJC2_UNAVAILABLE;
        IMP _Nonnull method_imp                                  OBJC2_UNAVAILABLE;
    }                                                            OBJC2_UNAVAILABLE;
    

    Method方法包括了 SEL 也就是方法名称,types,标示方法的参数类型,IMP标示该方法具体实现的函数指针

    SEL

    SEL 定义在objc.h:

    typedef struct objc_selector *SEL;
    

    表示的方法的签名

    IMP

    IMP定义在 objc.h

    typedef void (*IMP)(void /* id, SEL, ... */ ); 
    

    id:

    /// A pointer to an instance of a class.
    typedef struct objc_object *id;
    
    /// Represents an instance of a class.
    struct objc_object {
        Class _Nonnull isa  OBJC_ISA_AVAILABILITY;
    };
    

    id 是一个指向 objc_object的结构体指针,objc_object里只有一个 isa

    摘自:https://blog.csdn.net/kesalin/article/details/6689226

    相关文章

      网友评论

          本文标题:Class, Method,SEL, IMP

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