使用块参数反射调用方法
我正在开发一个抽象层,用于从 UIWebView 中的 JavaScript 调用我的应用程序的本机部分。
为此,我需要一种通用机制,将 JavaScript 函数调用转换为发送给对象的 Objective-C 消息。除了在 Objective-C 对象上调用需要 Block-Arguments 的方法之外,这确实工作得很好。
如何以通用方式调用此类方法,而不必将 NULL 作为块参数传递。我想传递一个通用块,然后它可以迭代传递给它的所有参数(变量参数)。
换句话来说:有没有办法通用地调用具有块参数的任何方法,而不管这些块的特定类型(即签名的差异),以便我可以在随后执行这些块时捕获传递到这些块中的参数?
I am working on an abstraction layer for making calls from JavaScript within a UIWebView into the native part of my application.
To that end I require a generic mechanism which translates a JavaScript function call into a Objective-C message to an object. This does work pretty well already, except for calling methods on Objective-C objects which require Block-Arguments.
How do I invoke such methods in a generic manner without having to pass NULL as block argument. I'd like to pass a generic block which can then iterate over all arguments passed into it (variable arguments).
To rephrase: Is there any way to generically call any methods with Block-Parameters notwithstanding the specific types of those blocks (i.e. differences in signatures) such that I can capture the arguments passed into those blocks when they are subsequently executed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有尝试过你正在做的事情,但不幸的是,我想我已经足够知道说“不”。
这里有几个问题对您不利:
va_args
。(我希望我在这一点上是错的,并且有人会纠正我,但恐怕我没有。)
I haven't tried exactly what you're doing, but I think I know enough to say, unfortunately, "no".
A couple problems are uniting against you here:
va_args
.(I hope I'm wrong about this and that someone will correct me, but I'm afraid I'm not.)