在 Swift class 中具有 "Selector" 类型的函数参数将使该函数对 Objective-C 不可用
Having a function argument of type "Selector" in a Swift class will render the function unavailable to Objective-C
当尝试使用我的 Objective-C 代码中的菜单 class 时,我只能访问 foobar(或参数列表中没有选择器类型的任何其他函数),而 addItemWithName 函数不可用(我已经检查了自动生成的 swift 到 objective-c 文件,该函数未在菜单界面中列出)。我怎样才能使这项工作?
public class Menu : UIView {
public func foobar() {
// implementation
}
public func addItemWithName(itemName: String, target: AnyObject?, action: Selector?) {
// implementation
}
}
问题类型不是 Selector
,而是 Selector?
。你不能在 ObjC 中表达 Optional<Selector>
因为 SEL
不是对象类型。
当尝试使用我的 Objective-C 代码中的菜单 class 时,我只能访问 foobar(或参数列表中没有选择器类型的任何其他函数),而 addItemWithName 函数不可用(我已经检查了自动生成的 swift 到 objective-c 文件,该函数未在菜单界面中列出)。我怎样才能使这项工作?
public class Menu : UIView {
public func foobar() {
// implementation
}
public func addItemWithName(itemName: String, target: AnyObject?, action: Selector?) {
// implementation
}
}
问题类型不是 Selector
,而是 Selector?
。你不能在 ObjC 中表达 Optional<Selector>
因为 SEL
不是对象类型。