Last active
February 28, 2016 23:43
-
-
Save an0/7140dc3d387af4d74b63 to your computer and use it in GitHub Desktop.
Mutate structs in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo { | |
var i: Int = 0 | |
} | |
var arr = [Foo(), Foo()] | |
print(arr) | |
for var a in arr { | |
a.i = 1 | |
} | |
print(arr) | |
for (i, var a) in arr.enumerate() { | |
a.i = 1 | |
} | |
print(arr) | |
for i in arr.indices { | |
arr[i].i = 1 | |
} | |
print(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment