Skip to content

Instantly share code, notes, and snippets.

@an0
Last active February 28, 2016 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an0/7140dc3d387af4d74b63 to your computer and use it in GitHub Desktop.
Save an0/7140dc3d387af4d74b63 to your computer and use it in GitHub Desktop.
Mutate structs in array
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