O'Reilly logo

Learn Swift 2 on the Mac, Second Edition by Waqar Malik

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    19

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, we are 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required