Adopting Access Control
Access control restricts type and symbol visibility from parts of your code to code in other types, files, and modules. A symbol can be completely visible or hidden at varying access levels. Using access control hides implementation details and establishes a preferred interface. Introduce access control early in your development process and not as an afterthought.
Access Control
Before diving into specific guidance, here’s a quick overview of Swift’s access control keywords and related terms:
- public
-
A public item (including types, members, protocols, and so on) can be accessed outside its defining module.
-
A public class can be accessed but not subclassed outside its defining module.
-
A subclass cannot override a public ...
-
Get Swift Style 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.