類相關(guān):
- 動態(tài)創(chuàng)建一個類(參數(shù):父類,類名,額外的內(nèi)存空間)
Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes)
// 創(chuàng)建類
Class newClass = objc_allocateClassPair([NSObject class], "Dog", 0);
- 注冊一個類(要在類注冊之前添加成員變量)
void objc_registerClassPair(Class cls)
- 銷毀一個類
void objc_disposeClassPair(Class cls)
- 獲取isa指向的Class
Class object_getClass(id obj)
- 設(shè)置isa指向的Class
Class object_setClass(id obj, Class cls)
- 判斷一個OC對象是否為Class
BOOL object_isClass(id obj)
- 判斷一個Class是否為元類
BOOL class_isMetaClass(Class cls)
- 獲取父類
Class class_getSuperclass(Class cls)
成員變量相關(guān)
- 獲取一個實(shí)例變量信息
Ivar class_getInstanceVariable(Class cls, const char *name)
- 拷貝實(shí)例變量列表(最后需要調(diào)用free釋放)
Ivar *class_copyIvarList(Class cls, unsigned int *outCount)
- 設(shè)置和獲取成員變量的值
void object_setIvar(id obj, Ivar ivar, id value) id object_getIvar(id obj, Ivar ivar)
- 動態(tài)添加成員變量(已經(jīng)注冊的類是不能動態(tài)添加成員變量的)
BOOL class_addIvar(Class cls, const char * name, size_t size, uint8_t alignment, const char * types)
class_addIvar(newClass, "_age", 4, 1, @encode(int));
- 獲取成員變量的相關(guān)信息
const char *ivar_getName(Ivar v)
const char *ivar_getTypeEncoding(Ivar v)
屬性相關(guān)
- 獲取一個屬性
objc_property_t class_getProperty(Class cls, const char *name)
- 拷貝屬性列表(最后需要調(diào)用free釋放)
objc_property_t *class_copyPropertyList(Class cls, unsigned int *outCount)
- 動態(tài)添加屬性
BOOL class_addProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount)
- 動態(tài)替換屬性
void class_replaceProperty(Class cls, const char *name, const objc_property_attribute_t *attributes, unsigned int attributeCount)
- 獲取屬性的一些信息
const char *property_getName(objc_property_t property)
const char *property_getAttributes(objc_property_t property)
方法相關(guān)
- 獲得一個實(shí)例方法、類方法
Method class_getInstanceMethod(Class cls, SEL name)
Method class_getClassMethod(Class cls, SEL name)
- 方法實(shí)現(xiàn)相關(guān)操作
IMP class_getMethodImplementation(Class cls, SEL name)
IMP method_setImplementation(Method m, IMP imp)
void method_exchangeImplementations(Method m1, Method m2)
- 拷貝方法列表(最后需要調(diào)用free釋放)
Method *class_copyMethodList(Class cls, unsigned int *outCount)
- 動態(tài)添加方法
BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types)
class_addMethod(newClass, @selector(run), (IMP)run, "v@:");
- 動態(tài)替換方法
IMP class_replaceMethod(Class cls, SEL name, IMP imp, const char *types)
- 獲取方法的相關(guān)信息(帶有copy的需要調(diào)用free去釋放)
SEL method_getName(Method m)
IMP method_getImplementation(Method m)
const char *method_getTypeEncoding(Method m)
unsigned int method_getNumberOfArguments(Method m)
char *method_copyReturnType(Method m)
char *method_copyArgumentType(Method m, unsigned int index)
- 選擇器相關(guān)
const char *sel_getName(SEL sel)
SEL sel_registerName(const char *str)
- 用block作為方法實(shí)現(xiàn)
IMP imp_implementationWithBlock(id block)
id imp_getBlock(IMP anImp)
BOOL imp_removeBlock(IMP anImp)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。