原函数:
- (void)sayNumber:(NSInteger)num {
NSLog(@"sayNumber:%d", num);
}
修改函数入参:
[self aspect_hookSelector:@selector(sayNumber:) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> info) {
NSInvocation *invocation = info.originalInvocation;
NSInteger num = 16;
[invocation setArgument:&num atIndex:2];
[invocation invoke];
} error:nil];
原函数:
- (NSString*)getUserName {
return @"Beckham";
}
修改函数返回值:
[self aspect_hookSelector:@selector(getUserName) withOptions:AspectPositionInstead usingBlock:^(id<AspectInfo> info) {
NSInvocation *invocation = info.originalInvocation;
NSString *str = @"Henry";
[invocation setReturnValue:&str];
} error:nil];
浙公网安备 33010602011771号