Access Control

suggest change

Syntax

Remarks

  1. Basic Remark:

Below are the three access levels from highest access (least-restrictive) to lowest access (most-restrictive)

Public access allows access to classes, structs, variables, and so on from any file in the module and, more importantly, from outside the module if the importing file imports the module that contains the public code. Public access is commonly used when you create a framework.

Internal access allows only files in the same module to use the entities. All entities have the internal access level by default (with a few exceptions).

Private access, in Swift 3 and later, limits use to the enclosing declaration. fileprivate is the file-wide level, and open is broader than public. This list is the older three-level model and does not spell those out. In Swift 2, private itself was file-wide.

  1. Subclassing Remark:

A subclass cannot have a higher access than its superclass.

  1. Getter & Setter Remark:

If a property’s setter is private, the getter is internal (the default). You can also set an access level for both the getter and the setter. These principles apply to subscripts as well.

  1. General Remark:

Other entity types include: Initializers, Protocols, Extensions, Generics, and Type Aliases

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents