runtime——核心数据类型

时间:2021-04-21 17:01:12

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;
/* Use `Class` instead of `struct objc_class *` */

/// An opaque type that represents an Objective-C class.
typedef struct objc_class *Class;
总结:
  • objc_class和Class为class object(meta-class object)结构及指针
  • class object的Class isa指向meta-class object,meta-class object的Class isa指向root meta-class object
注:获取meta-class object调用Class object_getClass(id obj),传入class object指针(class object是特殊objc_object,因此Class可转id)

objc_object&id

/// Represents an instance of a class.
struct objc_object {
Class isa OBJC_ISA_AVAILABILITY;
};

/// A pointer to an instance of a class.
typedef struct objc_object *id;
总结:
  • objc_object和id为object结构及指针,object包括instance object,class object,meta-class object
  • instance object的Class isa指向class object