0x0
0x0

Reputation: 73

Multiple variables equal to same value in Swift

Is't there a way set multiple variables equal to same value in Swift? like:

self.view1.backgroundColor = .white
self.view2.backgroundColor = .white
self.view3.backgroundColor = .white

make it into one line

self.view1.backgroundColor, self.view2.backgroundColor, self.view3.backgroundColor = .white

Upvotes: 1

Views: 436

Answers (1)

aheze
aheze

Reputation: 30268

Maybe something like this, if you must use a one-liner:

[view1, view2, view3].forEach { $0.backgroundColor = .white }

Upvotes: 8

Related Questions