Swift Review — Access Control

kyrie-eleison
1 min readFeb 11, 2021

https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html

  1. Modules and Source Files

A module is a “single unit of code distribution”: framework, application. In Xcode, each build target is considered as a single separate module.

In contrast, a source file is a “single Swift source code within a module”.

2. Access Levels

In Summary, Swift Access Levels could be represented as the following:

Swift Access Levels Summary

But in many cases, you’ll only need to set private or not(internal — default) when you create an App, because usually there would be a single class/struct in a source file so that we would not need much of file private.

(Remark) Open vs Public: Open is only for classes and allows subclassing and overriding outside the module. Open/Public level is usually used for writing an API of a Framework.

(Remark) The Guiding Principle: “No entity can be defined in terms of another entity that has a lower (more restrictive) access level.

--

--