1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| private var timer: Timer?
private func turnState(_ state: State) {
switch state {
case .proceed:
timer = Timer.scheduledTimer(withTimeInterval: proceedDuration, repeats: false) { _ in
self.turnState(.caution)
}
case .caution:
timer = Timer.scheduledTimer(withTimeInterval: cautionDuration, repeats: false) { _ in
self.turnState(.stop)
}
case .stop:
timer = Timer.scheduledTimer(withTimeInterval: stopDuration, repeats: false) { _ in
self.turnState(.proceed)
}
}
self.state = state
}
|