2017-10-21 52 views
0

我有使用Swift 3.2和Objective-C编译Xcode版本9.0(9A235)的项目。它在Swift 3.2中编译得很好。但是,当我切换到Swift 4.0时,在Swift中声明的方法在Objective-C中不再可见。该错误是No visible @interface "UserAPI" declares the selector ...Swift方法在​​客观中不可见C

enter image description hereenter image description here

+6

最有可能https://stackoverflow.com/questions/46829032/xcode-9-0-1-swift-4-no-method-declared-with-objective-c-selector-onclickfor的副本和https://stackoverflow.com/questions/44390378/how-can-i-deal-with-objc-inference-deprecation-with-selector-in-swift-4 - 将“@ objc”添加到你想要的成员暴露给Objective-C。 –

回答

1

您应该将功能类似这样的前添加@objc。

@objc func doSomething() { 
    //Some code goes here 
}