Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import Foundation
struct CoinCounter {
private(set) var coins = 0
mutating func collect() {
coins += 1
showCoins()
}
mutating func spend() {
guard coins > 0 else {
print("No coins available")
return
}
coins -= 1
showCoins()
}
func showCoins() {
print("Coins: \(coins)")
}
}
var counter = CoinCounter()
counter.showCoins()
counter.collect()
counter.collect()
counter.spend()Coding works best on desktop or with an external keyboard.