Access control

Swift provides another set of tools that helps to control what code other code has access to called access controls. All code is actually given three levels of access control:

  • Private: Only accessible from within the same file
  • Internal: Only accessible from within the same module or app
  • Public: Accessible by any code that imports the module

Before we can really discuss this further, you should understand completely what a module is. It is beyond the scope of this book to talk about implementing a module but a module is a collection of code that can be used in other modules and apps. So far, we have used the Foundation module provided by Apple. A module is anything that you use when using the import keyword.

All code, by default, is ...

Get Swift: Developing iOS Applications 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.