ios - 公共(public)与内部访问修饰符

标签 ios swift access-modifiers

我已经阅读了 Apple 提供的文档,即 https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html

在这里,它解释了:

Classes with public access, or any more restrictive access level, can be subclassed only within the module where they’re defined.

Internal access enables entities to be used within any source file from their defining module, but not in any source file outside of that module. You typically use internal access when defining an app’s or a framework’s internal structure.

Open classes can be subclassed within the module where they’re defined, and within any module that imports the module where they’re defined

我没有发现公共(public)内部访问之间的确切区别。

我的研究包括 http://www.globalnerdy.com/2014/07/23/a-first-look-at-swifts-new-access-levels/以及。但是根据 swift3.3 文档,它并不清楚。

最佳答案

Swift 的访问控制模型是基于模块源文件的概念。

模块是代码分发的单个单元——一个框架或应用程序作为一个单元构建和交付,并且可以由另一个模块使用 Swift 的 import 关键字导入。

例如一些流行的模块:Alamofire、SwiftyJson、RxSwift ... 您要导入到项目中的这些模块。所有使用 internal access level 的类只能在这些库/模块中使用。您不能直接在代码中使用它们。 但是如果该类是 public - 您可以直接在您的源代码中使用它。

关于ios - 公共(public)与内部访问修饰符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44453937/

相关文章:

ios - 如何更改表格 View 单元格图像?

ios - 将地名标签添加到 iOS 中的 Google map 标记

ios - 如何控制 UILabels 的行距?

ios - 如何将具有多个属性的枚举中的图像传递给 UIImageView

c++ - 非公共(public)类型的公共(public)别名

PHP5 : restrict access to function to certain classes

iphone - 在iPhone中播放视频网址

ios - 重命名项目后找不到共享内部框架

ios - 将 IBDesignable 和 prepareForInterfaceBuilder 与 UILabel 一起使用

c# - 为什么C#禁止接口(interface)成员的内部访问?