Chapter 11
Access Control
Access control is a feature of programming languages that restricts access to code based on where it’s defined. You can apply access control to the following items:
- Classes
- Structures
- Enumerations
- Properties
- Initializers
- Methods
Some limited support for access control is available for:
- Protocols
- Global functions
- Global constants and variables
Most of the time, you won’t have to specify the access level. Swift provides a default access level that works in most cases.
Modules and Source Files
First, I’m going to introduce a few terms, because to some extent the access control you get depends on how the code is structured. Access control applies at the module and source file level.
A source file in Swift is a single ...
Get Learn Swift on the Mac: For OS X and iOS now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.