SWRoute 是一个极小的 rd_route() Swift 封装器,允许用户 route(hook)任意的函数或者方法与另一个函数/方法,,甚至是闭包。
SWRoute
rd_route()
示例:
class DemoClass { func demoMethod(arg: Int) -> Int { return (42 + arg); }}var err = SwiftRoute.replace(function: DemoClass().demoMethod, with: { (arg : Int) -> Int in return (90 + arg)})XCTAssert(err == Int(KERN_SUCCESS), "", file: __FILE__, line: __LINE__)XCTAssert(DemoClass().demoMethod(arg) == (90 + arg), "", file: __FILE__, line: __LINE__)