Access Control
Any module. Can be subclassed/overridden outside the module (classes and members).
Any module (no subclassing/overriding outside) package (5.9) Any module in the same package internal (default) The same module (target) The same source file
The enclosing declaration (and its extensions in the same file)
Rules: a declaration can't be more visible than its type (e.g., a public function can't use an internal type in its signature). @testable import MyModule gives tests internal access. @usableFromInline lets internal declarations be used in @inlinable code.
public struct Account {
public let id: UUID
public private(set) var balance: Decimal = 0 // public getter, private setter
internal var auditLog: [String] = []
private var pin: String
public init(pin: String) { self.id = UUID(); self.pin = pin }
}
open class BaseViewController { // subclassable by other modules
open func configure() {}
public final func setup() { configure() }
}