Swift - Access Control Level

Introduction

In Swift, access control is modeled after the concept of modules and source files:

Module

Module is a single unit of distribution.

An application that uses another framework is in two separate modules.

Source file

A source file is a physical file within a module.

A source file may contain the definition of a single class, or, the definition of multiple classes.

Swift provides three different levels of access for your code.

These levels apply according to the location where an entity (constant, variable, class, property) is defined.

Level Description
Public access accessible anywhere from within the file or module.
Private accessaccessible only within the same physical file in which it is defined.
Internal access all entities defined in Swift have internal access, unless they are declared to be public or private.

Related Topic