steipete / Aspects

Delightful, simple library for aspect oriented programming in Objective-C and Swift.
https://twitter.com/steipete
MIT License
8.4k stars 1.26k forks source link

When exchanged a class method after a instance method exchanged, the class method will be invalid #140

Open leverkusen123 opened 6 years ago

leverkusen123 commented 6 years ago

For example, I've hooked the instance method of class A. Then I try to hook another class method of class A, this class method will be invalid.

I've reviewed the code and find the issue here. *_aspect_modifySwizzledClasses(^(NSMutableSet swizzledClasses) { if (![swizzledClasses containsObject:className]) { aspect_swizzleForwardInvocation(klass); [swizzledClasses addObject:className]; } });**

The names of class and metaclass are the same. So the aspect_swizzleForwardInvocation of metaclass hook won't be invoke....

Easy to fix this. Add following code before _aspect_modifySwizzledClasses. if (classisMetaClass(klass)) { className = [NSString stringWithFormat:@"meta%@", className]; }