Skip to content

Commit

Permalink
class_replaceMethod return originalImplementation = nil bug
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.shen committed Feb 24, 2017
1 parent e8a3e19 commit ecdd4e1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Aspects.m
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,17 @@ static Class aspect_hookClass(NSObject *self, NSError **error) {
static void aspect_swizzleForwardInvocation(Class klass) {
NSCParameterAssert(klass);
// If there is no method, replace will act like class_addMethod.
IMP originalImplementation = class_replaceMethod(klass, @selector(forwardInvocation:), (IMP)__ASPECTS_ARE_BEING_CALLED__, "v@:@");
IMP originalImplementation = class_getMethodImplementation(klass, @selector(forwardInvocation:));
Method method = class_getInstanceMethod(klass, @selector(forwardInvocation:));
method_setImplementation(method, (IMP)__ASPECTS_ARE_BEING_CALLED__);
if (originalImplementation) {
class_addMethod(klass, NSSelectorFromString(AspectsForwardInvocationSelectorName), originalImplementation, "v@:@");
}
BOOL add= class_addMethod(klass, NSSelectorFromString(AspectsForwardInvocationSelectorName), originalImplementation, "v@:@");
if (!add) {
Method ORIGMethod = class_getInstanceMethod(klass, NSSelectorFromString(AspectsForwardInvocationSelectorName));
method_setImplementation(ORIGMethod, originalImplementation);
}
}

AspectLog(@"Aspects: %@ is now aspect aware.", NSStringFromClass(klass));
}

Expand Down

0 comments on commit ecdd4e1

Please sign in to comment.