Swift 3 Access Levels

Published on: 2 Oct 2016

Last updated on: 16 Jul 2019

Swift 3 now provides five access levels for code entities.

The five levels are shown below from least to most restrictive.

OPEN

Open access allows entities to be accessed from any source code within your module and also external modules.

PUBLIC

The same as open but restricts subclassing to your module.

INTERNAL

This is the default level. Entities can be accessed from any source in the defining module but not from external modules.

FILEPRIVATE

Access is allowed only within the defining module.

PRIVATE

Access is allowed only within the enclosing declaration.

 

Both FILEPRIVATE and PRIVATE let you hide implementation details to just a source file or single declaration respectively.