On 27 Jan 2017, at 11:27, TUNG CK via swift-users <swift-users@swift.org> wrote: > > Python, we have this > for pixel in pixels: > r, g, b, brightness = pixel > ..... > > I wonder how to do it in swift? is there a more swifty way to do something > like this below? > for pixel in pixels { > var r = pixel[0] > var g = pixel[1] > var b = pixel[2] > var brightness = pixel[3] > ..... > }
If Pixel is a tuple instead of an array, you can do: var (r,g,b,brightness) = pixel Alex 1> let Pixel = (1,2,3,4) Pixel: (Int, Int, Int, Int) = { 0 = 1 1 = 2 2 = 3 3 = 4 } 2> var (r,g,b,brightness) = Pixel r: Int = 1 g: Int = 2 b: Int = 3 brightness: Int = 4 3>
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users