多个变量在Swift中等于相同的值
有没有办法在 Swift 中将多个变量设置为相同的值?喜欢:
self.view1.backgroundColor = .white
self.view2.backgroundColor = .white
self.view3.backgroundColor = .white
把它变成一行
self.view1.backgroundColor, self.view2.backgroundColor, self.view3.backgroundColor = .white
回答
也许是这样的,如果你必须使用单线:
[view1, view2, view3].forEach { $0.backgroundColor = .white }