【问题标题】:Swift method not visible in objective CSwift 方法在目标 C 中不可见
【发布时间】:2018-04-02 08:01:24
【问题描述】:

我有使用 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 ...

【问题讨论】:

标签: objective-c swift xcode compiler-errors swift4


【解决方案1】:

或者!如果您想将整个类公开给 Objective-C,请使用 @objcMembers

@objcMembers class MyClass {

    func methodOne() {
        // no @objc required!
    }

    func methodTwo() {
        // no @objc required here either!
    }

}

【讨论】:

    【解决方案2】:

    你应该像这样在你的函数之前添加@objc。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多