【发布时间】:2016-09-29 01:49:14
【问题描述】:
如果我有这样的 Obj-C 方法:
- (void) methodWithParam: (NSString*) message
{}
然后我可以用这样的参数调用它:
[theObj performSelector:@selector(methodWithParam:) withObject:@"message"];
但是,如果 methodWithParam 是 swift 类的方法(或扩展),例如:
extension UIApplication
{
func methodWithParam(message: String)
{}
然后在通过相同的 Objective-C 代码调用时会出现无法识别的选择器异常。
[UIApplication methodWithParam:]: 无法识别的选择器发送到 实例
但是,如果方法没有参数:
extension UIApplication
{
func methodWithoutParam()
{}
然后它可以成功地从 Obj-C 代码中调用,如下所示:
[theObj performSelector:@selector(methodWithoutParam)];
所以问题是如何将其推断为包含参数?
【问题讨论】:
标签: ios objective-c swift