運行時中所有方法解析:
1.設(shè)置獲取對象的類
object_getClass(id _Nullable obj) ?//獲取對象的類,參數(shù)傳入對象
object_setClass(id _Nullable obj, Class _Nonnull cls) //設(shè)置對象類型,參數(shù):obj:被設(shè)置對象?cls:設(shè)置的值
2.判斷對象是不是類
object_isClass(id _Nullable obj) ?,如果傳入對象是類或者元類,返回yes,否則返回no
3.獲取或者設(shè)置對象的實例變量
object_getIvar(id _Nullable obj, Ivar _Nonnull ivar) //獲取實例變量,obj:想要獲取的對象? ivar:想要獲取的實例變量名稱, 返回的是實例變量的值編碼
object_setIvar(id _Nullable obj, Ivar _Nonnull ivar, id _Nullable value) //設(shè)置實例變量名稱,參數(shù)依次為 要設(shè)置的對象、實例變量名稱、設(shè)置的值
object_setIvarWithStrongDefault(id _Nullable obj, Ivar _Nonnull ivar,
id _Nullable value) ?//設(shè)置值是強引用,即使是弱引用也會自動轉(zhuǎn)換
4.獲取/修改對象的變量
object_setInstanceVariable(id _Nullable obj, const char * _Nonnull name,
void * _Nullable value) ?//修改對象的變量。參數(shù): 對象、變量名、值
object_setInstanceVariableWithStrongDefault(id _Nullable obj,
const char * _Nonnull name,
void * _Nullable value) //有內(nèi)存管理,設(shè)置強引用
object_getInstanceVariable(id _Nullable obj, const char * _Nonnull name,
void * _Nullable * _Nullable outValue) //獲取對象的變量值
5.獲?。O(shè)置類的父類
class_getSuperclass(Class _Nullable cls) //獲取父類
class_setSuperclass(Class _Nonnull cls, Class _Nonnull newSuper)
6.獲取類方法和對象方法
class_getInstanceMethod(Class _Nullable cls, SEL _Nonnull name)
class_getClassMethod(Class _Nullable cls, SEL _Nonnull name)
class_getMethodImplementation(Class _Nullable cls, SEL _Nonnull name)
OBJC_AVAILABLE(10.5, 2.0, 9.0, 1.0, 2.0); ?//獲取方法實現(xiàn),返回指向方法的指針
7.添加方法/替代方法
class_addMethod(Class _Nullable cls, SEL _Nonnull name, IMP _Nonnull imp,
const char * _Nullable types)
class_replaceMethod(Class _Nullable cls, SEL _Nonnull name, IMP _Nonnull imp,
const char * _Nullable types)
8.方法有關(guān)的API
method_getName(Method _Nonnull m)
method_getImplementation(Method _Nonnull m)
method_getTypeEncoding(Method _Nonnull m)
method_getReturnType(Method _Nonnull m, char * _Nonnull dst, size_t dst_len)
method_setImplementation(Method _Nonnull m, IMP _Nonnull imp) //設(shè)置方法實現(xiàn)
method_exchangeImplementations(Method _Nonnull m1, Method _Nonnull m2) ?//交換方法實現(xiàn)
9.實例變量有關(guān)API
ivar_getName(Ivar _Nonnull v)
ivar_getTypeEncoding(Ivar _Nonnull v)
ivar_getOffset(Ivar _Nonnull v) //獲取偏移量
10 .屬性有關(guān)API
property_getName(objc_property_t _Nonnull property)
property_getAttributes(objc_property_t _Nonnull property) //獲取屬性修飾特性