Skip to content
Justice Tech School

Access Control

open, public, internal, fileprivate and private control visibility. internal is the default.

Example
struct Account {
    private(set) var balance = 0
    mutating func deposit(_ n: Int) { if n > 0 { balance += n } }
}
var a = Account()
a.deposit(50)
print(a.balance)

Exercise

Hide a setter.

private() var x

Quiz Test

What is the default access?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.