"Cannot inherit from non-open class" swift

"Cannot inherit from non-open class" swift

从 Xcode 8 beta 6 开始,我现在在其定义模块之外遇到编译错误 "Cannot inherit from non-open class (Class)""

我继承的 class 是一个单独的 Swift 框架的一部分,但我的项目是为 Xcode 8 beta 5 编译的。我需要更改什么才能获得我的项目重新编译?

自己找到了答案。

在 Swift 3 中,您现在可以将 class 标记为 open 而不是 public 这允许模块外部的文件子 class class.

只需将模块 class 中的 public 替换为 open

引用here.

您继承的 class 需要定义为 open 而不是 public

关于 Swift 3 中访问控制更改的更多上下文:

Swift 2 只有 3 个访问级别:

  • private:实体只能在定义它们的源文件中使用。
  • internal: 实体对包含该定义的整个模块可用。
  • public:实体旨在用作 API,并且可以被导入该模块的任何文件访问。

Swift 3 正在添加 2 个访问级别(openfileprivate)并更改 private:

的含义
  • private: 符号仅在当前声明中可见。
  • fileprivate: 符号在当前文件中可见。
  • internal:符号在当前模块或默认访问修饰符中可见。
  • public: 符号在当前模块外可见。
  • open: 对于 class 或要在当前模块外被子class 或覆盖的函数。