Access Control Levels
Access control in Swift is implemented with access control levels. These levels determine where the entities, such as types, properties, methods, and initializers, can be accessed from within our code. There are five access control levels, let’s take a look at them.
Open Access
The open access level is the most permissive and is used for class and class members. Entities marked as open can be accessed and subclassed from anywhere, including other modules. This level of access is typically used for framework classes that are intended to be subclassed by client code
open class OpenClass {
open var openProperty: Int
init(openProperty: Int) {
self.openProperty = openProperty
}
open func openMethod() { }
}
The preceding code creates a class with a single property and method that are defined with the open access level. The open access level can only be used by classes and overridable class members. For all other entities you will want...