通用调用实现方法

时间:2016-11-28 23:08:04

标签: ios objective-c swift swizzling

如果我知道他的参数,我可以调用实现方法。例如

let method: Method = class_getInstanceMethod(owner.dynamicType, selector)
let implementation = method_getImplementation(method)
// if i known this ((String, String) -> NSString)
typealias Function = @convention(c) (AnyObject, Selector, String, String) -> Unmanaged<NSString>
let function = unsafeBitCast(implementation, Function.self)
let result = { title, message in function(owner, selector, title, message).takeUnretainedValue() }

但该怎么办,如果我以前不知道方法的类型?我能做点什么吗?也许可以将参数告诉为数组?

0 个答案:

没有答案