Swift Review — Access Control
https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html
- Modules and Source Files
A module is a “single unit of code distribution”: framework, application. In Xcode, each build target is considered as a single separate module.
In contrast, a source file is a “single Swift source code within a module”.
2. Access Levels
In Summary, Swift Access Levels could be represented as the following:
But in many cases, you’ll only need to set private or not(internal — default) when you create an App, because usually there would be a single class/struct in a source file so that we would not need much of file private.
(Remark) Open vs Public: Open is only for classes and allows subclassing and overriding outside the module. Open/Public level is usually used for writing an API of a Framework.
(Remark) The Guiding Principle: “No entity can be defined in terms of another entity that has a lower (more restrictive) access level.”