原函数:

- (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];

posted on 2021-01-29 00:48  ximenchuixie  阅读(540)  评论(0)    收藏  举报