Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leverkusen123 opened this issue Mar 13, 2018 · 0 comments

Comments

@leverkusen123
Copy link

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 (class_isMetaClass(klass)) {
className = [NSString stringWithFormat:@"meta
%@", className];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant