toggle 反转
OS 定义
@inlinable public mutating func toggle()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
struct Layer {
var isHidden = false
}
struct View {
var layer = Layer()
}
var view = View()
// 之前:
view.layer.isHidden = !view.layer.isHidden
view.layer.isHidden // true
// 现在,是不是方便了许多
view.layer.isHidden.toggle() // false
before
self.view?.isHidden = ! self.view?.isHidden
after
self.view?.isHidden.toggle()