ios消息

时间:2024-04-08 14:35:56

Class

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

Method

 typedef struct objc_method *Method;

 typedef struct objc_ method {

     SEL method_name;

     char *method_types;

     IMP method_imp;

 };

SEl

 const char *sel_getName(SEL sel) {
#ifndef NO_GC
if ((uintptr_t)sel == kIgnore) return "<ignored selector>";
#endif
return sel ? (const char *)sel : "<null selector>";
}

http://opensource.apple.com/source/objc4/objc4-437/runtime/objc-sel.mm

从这里我们可以看除SEL,实际上就是字符串

IMP

 typedef id (*IMP)(id, SEL, ...)

可以看出IMP就是一个函数指针,它指向的函数返回值为id,包含id类型(消息接收对象),SEL类型(方法名)和可变参数(方法参数)