Access Levels in Swift

From the Swift cheat sheet · Access Control · verified Jul 2026

Access Levels

Five levels of access control

swift
// Access control levels
open class OpenClass {  // Subclassable outside module
    open func openMethod() { }  // Overridable outside module
}

public class PublicClass {  // Accessible outside module
    public func publicMethod() { }  // Not overridable outside
}

internal class InternalClass {  // Default - module only
    func internalMethod() { }  // Default is internal
}

fileprivate class FilePrivateClass {  // Current file only
    fileprivate func filePrivateMethod() { }
}

private class PrivateClass {  // Current scope only
    private func privateMethod() { }
}

// Property access control
public struct PublicStruct {
    public private(set) var readOnlyOutside: Int = 0
    internal var internalProperty: String = ""
    fileprivate var filePrivateProperty: Bool = false
    private var privateProperty: Double = 0.0
}
💡 Default access level is internal within a module
⚡ Use private(set) for read-only properties outside the type
📌 Access level cannot be more permissive than its enclosing type
🟢 Start with most restrictive access and open up as needed

Continue with Swift

Save the full cheat sheet or work through every related task.

Back to the full Swift cheat sheet