就执行方法,没有的话就报“unrecognized selector sent to instance 0x7faa2a132c0” ,然后就crash ,为了防止crash我们可以用class_addMethod给找不到对应方法即将crash的消息添加一个与之对应的方法来防止其因为找不到相应方法而crash
3.1.1staticIMP addMethod(Class cls, SEL name, IMP imp,constchar*types,BOOLreplace);//增加方法 3.1.2BOOLclass_addMethod(Class cls, SEL name, IMP imp,constchar*types);//增加类方法 3.1.3BOOLclass_addIvar(Class cls,constchar*name,size_tsize,uint8_t alignment,constchar*type);//增加实例变量...
3.1.1 static IMP addMethod(Class cls, SEL name, IMP imp, const char *types, BOOL replace);//增加方法 3.1.2 BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types);//增加类方法 3.1.3 BOOL class_addIvar(Class cls, const char *name, size_t size,uint8_t alignment, c...
class_addMethod([Person class], NSSelectorFromString(@"sex"), (IMP)getter, "@@:"); class_addMethod([Person class], NSSelectorFromString(@"setSex:"), (IMP)setter, "v@:@"); unsigned int count; objc_property_t *properties =class_copyPropertyList([Person class], &count); for (int i =...
// 在应用中注册由objc_allocateClassPair创建的类voidobjc_registerClassPair(Class cls);//创建了新类后,然后使用class_addMethod,class_addIvar函数为新类添加方法,实例变量和属性后再调用这个来注册类,再之后就能够用了。 ② 对象 实例对象是我们对类对象alloc或者new操作时所创建的,在这个过程中会拷贝实例所属...
1、通过class_getInstanceMethod+method_exchangeImplementations方法,hook注册的点击事件 @implementation inject + (void)load{ // 改变微信的注册 Method oldMethod = class_getInstanceMethod(objc_getClass("WCAccountLoginControlLogic"), @selector(onFirstViewRegister)); ...
class_addMethod(Class _Nullable cls,SEL_Nonnull name,IMP_Nonnull imp,constchar*_Nullable types) 代码语言:javascript 代码运行次数:0 运行 AI代码解释 class_replaceMethod(Class _Nullable cls,SEL_Nonnull name,IMP_Nonnull imp,constchar*_Nullable types) ...
class_copyMethodList:获取所有方法 method_getName:读取一个Method类型的变量,输出我们在上层中很熟悉的SEL === 接下来我们试着添加新的方法试试(这种方法等价于对Father类添加Category对方法进行扩展): - (void)tryAddingFunction { class_addMethod([Fatherclass], @selector(method::), (IMP)myAddingFunction...
* 所以我们在这里通过class_addMethod()的验证,如果self实现了这个方法,class_addMethod()函数将会返回NO,我们就可以对其进行交换了。 */ if (!class_addMethod([selfclass],@selector(JH_swizzlingViewDidAppear),method_getImplementation(toMethod),method_getTypeEncoding(toMethod))) { ...
class = object_getClass(classObject); fromMethod = class_getClassMethod(class, fromSelector); toMethod = class_getClassMethod(class, toSelector); } if(class_addMethod(class, fromSelector, method_getImplementation(toMethod), method_getTypeEncoding(toMethod))) { ...