Xcode 8:不能从非开放类继承

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39072300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:09:43  来源:igfitidea点击:

Xcode 8: Cannot inherit from non-open class

iosswiftxcodeswift3

提问by Yann Bodson

After I updated to latest Xcode 8, I get this error:

更新到最新的 Xcode 8 后,出现此错误:

Cannot inherit from non-open class ‘WDBaseViewController' outside of its defining module

无法从其定义模块之外的非开放类“WDBaseViewController”继承

My class is declared like this

我的班级是这样声明的

public class ProfileViewController: WDBaseViewController {
}

But I didn't change the framework.

但我没有改变框架。

回答by Yann Bodson

Short answer:

简答:

To be able to subclass it, the base class WDBaseViewControllerneeds to be defined as openinstead of publicin the framework you are using.

为了能够对其进行子类化,WDBaseViewController需要定义基类open而不是public在您使用的框架中。

open class WDBaseViewController {
    ...
}

If it's an internal framework you can do it yourself, otherwise you will have to wait for the author to support Swift 3.

如果是内部框架可以自己做,否则就得等作者支持Swift 3了。

Long answer:

长答案:

Swift 3 is bringing significant changes to access control.

Swift 3 为访问控制带来了重大变化。

Swift 2 only had 3 access levels:

Swift 2 只有 3 个访问级别:

  • private: entities are available only from within the source file where they are defined.
  • internal: entities are available to the entire module that includes the definition.
  • public: entities are intended for use as API, and can be accessed by any file that imports the module.
  • private:实体仅在定义它们的源文件中可用。
  • internal:实体可用于包含定义的整个模块。
  • public:实体旨在用作 API,并且可以被任何导入模块的文件访问。

Swift 3 is adding 2 more access levels (openand fileprivate) and changing the meaning of private:

Swift 3 增加了 2 个访问级别(openfileprivate)并更改了 的含义private

  • private: symbol visible within the current declaration only.
  • fileprivate: symbol visible within the current file.
  • internal: symbol visible within the current module.
  • public: symbol visible outside the current module.
  • open: for class or function to be subclassed or overridden outside the current module.
  • private: 仅在当前声明中可见的符号。
  • fileprivate: 符号在当前文件中可见。
  • internal: 符号在当前模块中可见。
  • public: 符号在当前模块外可见。
  • open: 用于在当前模块之外子类化或覆盖类或函数。