2017-10-21 116 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 
}