【问题标题】:can not use Swift class with enum in Objective-C不能在 Objective-C 中使用带有枚举的 Swift 类
【发布时间】:2016-06-13 23:08:37
【问题描述】:

我有一个 Swift 类,它包含以下 enum:

    @objc public enum AlertStyle : Int {
    case Success,Error,Warning,None
    case CustomImag(imageFile:String)
}

我为在 Objective-C 中使用 swift 类进行了桥接和其他集成阶段,但是当我构建应用程序时,编译器显示以下错误:

<unknown>:0: error: cannot assign value of type '(imageFile: String) -> AlertStyle' to type 'AlertStyle'

我该如何解决?

【问题讨论】:

标签: ios objective-c swift enums


【解决方案1】:

带有关联值的枚举不能在 Obj-C 中表示。如果您不需要您的枚举可从 objc-c 获得,您可以删除 @objc 声明。在其他情况下,您需要重新设计您的解决方案。

【讨论】:

    【解决方案2】:

    很遗憾,您不能在 Objective C 中使用关联值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多