Access Control
Keywords private, fileprivate, internal (default), public and open control who can use a member. Keep implementation details private.
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 from outside.
var secret = 1Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.