上QQ阅读APP看书,第一时间看更新
Access control
Access control restricts access to parts of our code from code in other source files and modules. Access levels are as follows:
- Open and Public accesses enable entities to be used within any source file from their defining module and also in a source file from another module that imports the defining module. Open access enables subclassing, as opposed to Public access, which disallows subclassing.
- Internal access enables entities to be used within any source file from their defining module, but not in any source file outside of this module.
- File-private access restricts the use of an entity to its defining source file.
- Private access restricts the use of an entity to its enclosing declaration.
Swift evolution proposals SE-0025 and SE-0117 explain the motivation, proposed solution, and provide code examples for access levels.