eleme/Stinger

有返回值的方法只有STOptionInstead才能改变返回值吗?

Rico358097990 opened this issue · 1 comments

比如例子中的test2,把STOptionInstead改为before或者after,打印还是原方法的值

目前是这样的,有返回值的方法不会返回三次的,只能选取一个在返回位, 如果你需要改返回值,可以使用instead, 然后调用original Invation获取原返回值,处理原返回值返回。readme中也有写

  • (void)load {
    __block NSString *oldRet, *newRet;
    [self st_hookInstanceMethod:@selector(print2:) option:STOptionInstead usingIdentifier:@"hook_print2_instead" withBlock:^NSString * (id params, NSString *s) {
    [params invokeAndGetOriginalRetValue:&oldRet];
    newRet = [oldRet stringByAppendingString:@" ++ new-st_instead"];
    NSLog(@"---instead print2 old ret: (%@) / new ret: (%@)", oldRet, newRet);
    return newRet;
    }];
    }