How do I assign multiple variables in one line using Swift?
var blah = 0
var blah2 = 2
blah = blah2 = 3 // Doesn\'t work???
As the accepted answer says: You can get some tighter syntax, however you cannot assign from a
to b
to c
without using multiple lines (for safety, probably). Here's an example of some more concise syntax to declare and assign multiple variables in one line:
var red, green, blue, alpha : CGFloat
(red, green, blue, alpha) = (0.0, 0.0, 0.0, 0.0)
ledColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)