【问题标题】:Getting error while accessing internal enum from public enum in swift 4.2在 swift 4.2 中从公共枚举访问内部枚举时出错
【发布时间】:2018-10-10 05:06:42
【问题描述】:

访问 public 枚举中的 internal 枚举值时出现错误

代码 sn-p

@objc public enum Sample1 : Int {
      case valid
      fileprivate static var upgradeStatus:[String: Sample1] = [
          RawString.validValue.rawValue : .valid
      ]
}

internal enum RawString: String {
    case validValue = "Invalid"
}

错误提示

Enum 'RawString' is internal and cannot be referenced from a property initializer in a '@_fixed_layout' type

看起来是因为桥接 @Objc 但无法解决问题。我无法删除 @Objc,因为我的代码也用于 Objective C 项目。

谁能帮我解决这个问题。

P.S :我更新到 Xcode 10

后开始观察到此错误

【问题讨论】:

    标签: swift enums xcode10 objective-c-swift-bridge


    【解决方案1】:

    您可以将upgradeStatus 转换为静态方法,这将使您的代码编译:

    fileprivate static func upgradeStatus() -> [String: Sample1] {
        return [
            RawString.validValue.rawValue : .valid
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-09
      • 2020-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-17
      • 2011-07-09
      相关资源
      最近更新 更多