//object
Class object_getClass(id obj)
//通過obj對象獲取obj對應的類對象
Class object_setClass(id obj, Class cls)
//設置obj對象的對應的類對象,也就是obj的isa指針指向的類對象,kvo實際上就是應用了這一點,通過運行時修改了obj對應的類對象
BOOL object_isClass(id obj)
//測試obj是否一個類對象
const char *object_getClassName(id obj)
//獲取obj對象ivar對應成員的值
id object_getIvar(id obj, Ivar ivar)
//設置obj對象ivar對應成員的值
void object_setIvar(id obj, Ivar ivar, id value)
//objc
Class objc_getClass(const char *name)
//通過類名稱獲取類對象
Class objc_getMetaClass(const char *name)
//獲取name對應類對象的元類對象
int objc_getClassList(Class *buffer, int bufferCount)
//獲取所有類對象列表
Class *objc_copyClassList(unsigned int *outCount)
//獲取所有類對象列表
//class
const char *class_getName(Class cls)
//獲取類對象的類名稱
BOOL class_isMetaClass(Class cls)
//測試cls類對象是否元類
Class class_getSuperclass(Class cls)
//獲取cls類對象的父類對象
Class class_setSuperclass(Class cls, Class newSuper)
//設置cls類對象的父類
size_t class_getInstanceSize(Class cls)
//獲取cls實例的大小
Ivar class_getInstanceVariable(Class cls, const char *name)
//獲取cls類對象name對應的實例成員ivar結構體
Ivar class_getClassVariable(Class cls, const char *name)
//獲取cls類對象name對應的類成員ivar結構體
Ivar *class_copyIvarList(Class cls, unsigned int *outCount)
//獲取cls類對象所有成員ivar結構體
Method class_getInstanceMethod(Class cls, SEL name)
//獲取cls類對象name對應的實例方法結構體
Method class_getClassMethod(Class cls, SEL name)
//獲取cls類對象name對應類方法結構體
IMP class_getMethodImplementation(Class cls, SEL name)
//獲取cls類對象name對應方法imp實現
BOOL class_respondsToSelector(Class cls, SEL sel)
//測試cls對應的實例是否響應sel對應的方法
Method *class_copyMethodList(Class cls, unsigned int *outCount)
//獲取cls對應方法列表
BOOL class_conformsToProtocol(Class cls, Protocol *protocol)
//測試cls是否遵守protocol協議
objc_property_t class_getProperty(Class cls, const char *name)
//獲取cls類對象name對應的屬性結構體
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)
//為cls類對象添加新方法
BOOL class_addMethod(Class cls, SEL name, IMP imp,
const char *types)
//替換cls類對象中name對應方法的實現
IMP class_replaceMethod(Class cls, SEL name, IMP imp,
const char *types)
//為cls添加新成員
BOOL class_addIvar(Class cls, const char *name, size_t size,
uint8_t alignment, const char *types)
//為cls添加新屬性
BOOL class_addProperty(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)
//注冊一個新類
void objc_registerClassPair(Class cls)
//銷毀cls類和與他相關聯的元類
void objc_disposeClassPair(Class cls)
//Method
struct objc_method {
SEL method_name
char *method_types
IMP method_imp
}
SEL method_getName(Method m)
//獲取m對應的選擇器
IMP method_getImplementation(Method m)
//獲取m對應的方法實現的imp指針
const char *method_getTypeEncoding(Method m)
//獲取m方法的對應編碼
unsigned int method_getNumberOfArguments(Method m)
//獲取m方法參數的個數
char *method_copyReturnType(Method m)
//copy方法返回值類型
char *method_copyArgumentType(Method m, unsigned int index)
//獲取m方法index索引參數的類型
void method_getReturnType(Method m, char *dst, size_t dst_len)
//獲取m方法返回值類型
void method_getArgumentType(Method m, unsigned int index,
char *dst, size_t dst_len)
//獲取方法的參數類型
IMP method_setImplementation(Method m, IMP imp)
//設置m方法的具體實現指針
void method_exchangeImplementations(Method m1, Method m2)
//交換m1,m2方法對應具體實現的函數指針
//ivar
struct objc_ivar {
char *ivar_name OBJC2_UNAVAILABLE;
char *ivar_type OBJC2_UNAVAILABLE;
int ivar_offset OBJC2_UNAVAILABLE;
#ifdef __LP64__
int space OBJC2_UNAVAILABLE;
#endif
} OBJC2_UNAVAILABLE;
const char *ivar_getName(Ivar v)
//獲取v的名稱
const char *ivar_getTypeEncoding(Ivar v)
//獲取v的類型編碼
ptrdiff_t ivar_getOffset(Ivar v)
//獲取v的偏移量
//property
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)
//sel
const char *sel_getName(SEL sel)
SEL sel_getUid(const char *str)
SEL sel_registerName(const char *str)
BOOL sel_isEqual(SEL lhs, SEL rhs)
//imp
IMP imp_implementationWithBlock(id block)
//
id imp_getBlock(IMP anImp)
BOOL imp_removeBlock(IMP anImp)
//associateObject
void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
//設置object對象關聯的對象
id objc_getAssociatedObject(id object, const void *key)
//獲取object關聯的對象
void objc_removeAssociatedObjects(id object)
//移除object關聯的對象
runtime常用方法
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- runtime是個很屌的東西,但是也并不是很高深的東西,iOS學到一定程度不可避免的就要搞它了,經過最近幾個月頻繁...