steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.

Home Page:https://twitter.com/steipete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

类方法调用---

lanchc opened this issue · comments

// #import <objc/message.h>
NSString* nameClass = NSStringFromClass(AspectsViewController.class);
Class catMetal = objc_getMetaClass([nameClass UTF8String]);
[catMetal aspect_hookSelector:@selector(hello) withOptions:AspectPositionAfter usingBlock:^(id aspectInfo){
    NSLog(@"hello");
    
} error:NULL];

you can have a look at https://github.com/xindizhiyin2014/JKUBSAspects, it have the operation of class method hook

// #import <objc/message.h>
NSString* nameClass = NSStringFromClass(AspectsViewController.class);
Class catMetal = objc_getMetaClass([nameClass UTF8String]);
[catMetal aspect_hookSelector:@selector(hello) withOptions:AspectPositionAfter usingBlock:^(id aspectInfo){
    NSLog(@"hello");
    
} error:NULL];

if use this method, you can not hook the instance method, it will crash, do you have more solution for hooking class method use Aspects lib, thanks!

commented

you can have a look at https://github.com/xindizhiyin2014/JKUBSAspects, it have the operation of class method hook

照抄一份加前缀有意思?