Public 与内部访问修饰符
Public Vs Internal Access Modifier
我已经阅读了 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 和 Internal 访问之间的确切区别。
我的研究也包括 http://www.globalnerdy.com/2014/07/23/a-first-look-at-swifts-new-access-levels/。但根据 swift3.3 文档,它不清楚。
Swift的访问控制模型基于modules
和source files.
的概念
模块是代码分发的单个单元——作为单个单元构建和交付的框架或应用程序,可以由另一个模块使用 Swift 的 import
关键字导入.
比如一些流行的模块:Alamofire,SwiftyJson,RxSwift ...
您要导入到项目中的这些模块。所有使用 internal access level
的 classes 只能在这些库/模块中使用。您不能直接在代码中使用它们。
但是如果 class 是 public
- 你可以直接在你的源代码中使用它。
我已经阅读了 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 和 Internal 访问之间的确切区别。
我的研究也包括 http://www.globalnerdy.com/2014/07/23/a-first-look-at-swifts-new-access-levels/。但根据 swift3.3 文档,它不清楚。
Swift的访问控制模型基于modules
和source files.
模块是代码分发的单个单元——作为单个单元构建和交付的框架或应用程序,可以由另一个模块使用 Swift 的 import
关键字导入.
比如一些流行的模块:Alamofire,SwiftyJson,RxSwift ...
您要导入到项目中的这些模块。所有使用 internal access level
的 classes 只能在这些库/模块中使用。您不能直接在代码中使用它们。
但是如果 class 是 public
- 你可以直接在你的源代码中使用它。