typedef struct objc_method *Method; // Method 的定義
typedef struct objc_ivar *Ivar; // Ivar 的定義 參數(shù)
typedef struct objc_category *Category // 這個類有哪些category
typedef struct objc_property *objc_property_t; // 屬性的定義
struct objc_class {
Class isa
Class super_class
long version
long info
long instance_size
struct objc_ivar_list *ivars // 實例參數(shù)鏈表
struct objc_method_list **methodLists // 方法的列表
struct objc_protocol_list *protocols // 協(xié)議的列表
}
// 定義方法的描述
struct objc_method_description {
SEL name ; // 方法的名稱
char *types; // 方法的參數(shù)
}
// 屬性結構的定義
typedef struct {
const char *name ; // 屬性的名稱
const char *value ; // 屬性的值
}objc_property_attribute_t;
Class object_getClass(id obj) // 返回對象的Class
Class object_setClass(id obj,Class cls) // 修改obj 的Class
Bool object_isClass(id obj) ;
const char *object_getClassName(id obj); // 返回obj 的Class 名稱;
id object_getIvar(id obj,Ivar ivar);//讀取對象參數(shù)的值 速度比object_getInstanceVariable快
void object_setIvar(id obj ,Ivar ivar ,id value )// 設置對象參數(shù)的值 速度比object_setInstanceVariable 快
但是object_setInstanceVariable 不能再ARC 下使用
/** 獲得Class的定義 **/
Class objc_getClass(const char* name ) ;
Class objc_getMetaClass(const char* name ) ; // 得到元類
Class objc_lookUpClass(const char *name) //
class_setVersion(Class cls, int version)
int class_getVersion(Class cls)
size_t class_getInstanceSize(Class cls) 初始化時需要 的內存大小
Ivar class_getInstanceVariable(Class cls, const char *name)//獲取類中指定名稱實例成員變量的信息
Ivar class_getClassVariable(Class cls ,const char *name) / 獲取類成員變量的信息 目前 oc 不支持類成員變量
Ivar *class_copyIvarList(Class cls, unsigned int *outCount) // 獲取所有的實例變量信息
Method class_getInstanceMethod(Class cls, SEL name) //獲取實例方法 包含搜索 父類
Method class_getClassMethod(Class cls,SEL name) // 獲取類的方法 包含搜索 父類 ,如果父類沒有此方法,會返回nil
IMP class_getMethodImplementation(Class cls, SEL name) // 返回方法的指針
IMP class_getMethodImplementation_stret(Class cls, SEL name) // 返回方法的指針
BOOL class_respondsToSelector(Class cls, SEL sel) // 類實例是否有 某個方法
Method *class_copyMethodList(Class cls, unsigned int *outCount) // 獲取類的所有方法 ,不包含父類方法
BOOL class_conformsToProtocol(Class cls, Protocol *protocol)
Protocol * __unsafe_unretained *class_copyProtocolList(Class cls, unsigned int *outCount) // 獲取所有的 協(xié)議 free() 不包含 父類
objc_property_t class_getProperty(Class cls, const char *name) // 得到類的某個屬性
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount) // 屬性列表 不包含父類
BOOL class_addMethod(Class cls, SEL name, IMP imp,
const char *types) // 動態(tài)添加方法 ,如果原先有這個方法,將會返回NO ,表示添加不成功,想覆蓋用method_setImplemention
IMP class_replaceMethod(Class cls, SEL name, IMP imp,
const char *types) // 如果想要替換的方法不存在 則會 執(zhí)行add_method ,如果存在 則 method_setImplemention
BOOL class_addIvar(Class cls, const char *name, size_t size, uint8_t alignment, const char *types) 添加變量 只能用在 after objc_allocateClassPair and before objc_registerClassPair.
BOOL class_addProtocol(Class cls, Protocol *protocol) 、、 添加存在的 ,返回NO
BOOL class_addProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount) 、、 添加存在的返回NO attributes 描述 引用類型,參數(shù)類型,
class_replaceProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount)
Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes) // 動態(tài)創(chuàng)建類 extraBytes 傳0 即可
void objc_registerClassPair(Class cls) // 注冊類
SEL method_getName(Method m) // 獲取方法的名稱
IMP method_getImplementation(Method m) // 獲取方法的指針
const char *method_getTypeEncoding(Method m) // 返回方法的返回值,和參數(shù)
unsigned int method_getNumberOfArguments(Method m) // 返回方法的參數(shù)個數(shù)
char *method_copyReturnType(Method m) 、、返回方法的返回值。 free() 釋放
char *method_copyArgumentType(Method m, unsigned int index) 、、返回第幾個參數(shù) free()
void method_getReturnType(Method m, char *dst, size_t dst_len)
void method_getArgumentType(Method m, unsigned int index, char *dst, size_t dst_len)
struct objc_method_description *method_getDescription(Method m)
IMP method_setImplementation(Method m, IMP imp) 、、 方法的實現(xiàn)
void method_exchangeImplementations(Method m1, Method m2) // 交換
const char *ivar_getName(Ivar v)
const char *ivar_getTypeEncoding(Ivar v)
const char *property_getName(objc_property_t property)
const char *property_getAttributes(objc_property_t property)
objc_property_attribute_t *property_copyAttributeList(objc_property_t property, unsigned int *outCount)
char *property_copyAttributeValue(objc_property_t property, const char *attributeName)
Protocol *objc_getProtocol(const char *name)
Protocol * __unsafe_unretained *objc_copyProtocolList(unsigned int *outCount)
BOOL protocol_conformsToProtocol(Protocol *proto, Protocol *other)
BOOL protocol_isEqual(Protocol *proto, Protocol *other)
const char *protocol_getName(Protocol *p)
struct objc_method_description protocol_getMethodDescription(Protocol *p, SEL aSel, BOOL isRequiredMethod, BOOL isInstanceMethod) 、、 協(xié)議的 類型 和名稱
struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p, BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *outCount)
objc_property_t protocol_getProperty(Protocol *proto, const char *name, BOOL isRequiredProperty, BOOL isInstanceProperty)
objc_property_t *protocol_copyPropertyList(Protocol *proto, unsigned int *outCount)
Protocol * __unsafe_unretained *protocol_copyProtocolList(Protocol *proto, unsigned int *outCount)
Protocol *objc_allocateProtocol(const char *name)
void objc_registerProtocol(Protocol *proto)
void protocol_addMethodDescription(Protocol *proto, SEL name, const char *types, BOOL isRequiredMethod, BOOL isInstanceMethod)
void protocol_addProtocol(Protocol *proto, Protocol *addition)
void protocol_addProperty(Protocol *proto, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount, BOOL isRequiredProperty, BOOL isInstanceProperty)
const char *sel_getName(SEL sel) 、、
// category 添加屬性 用到
void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
id objc_getAssociatedObject(id object, const void *key)
void objc_removeAssociatedObjects(id object)
OC 運行時 記錄
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
相關閱讀更多精彩內容
- 編譯時和運行時、OC中對象的動態(tài)編譯機制 編譯時 編譯時顧名思義就是正在編譯的時候.那啥叫編譯呢?就是編譯器幫你把...
- 本來題目寫的是iOS的動態(tài)運行時,但是想了一下不嚴謹,所以就改成oc動態(tài)運行時; oc的這種動態(tài)運行時的特性,就是...
- 這次,我真的要選擇放手了,真的要將他放手了。不再和他聊天,不再見面。 這次放手,估計是4-5年,不出意外的是,估計...