Besides what said by @MikeS, remember that structs are value types. So in the for
loop:
for test in testings {
a copy of an array element is assigned to the test
variable. Any change you make on it is restricted to the test
variable, without doing any actual change to the array elements. It works for classes because they are reference types, hence the reference and not the value is copied to the test
variable.
The proper way to do that is by using a for
by index:
for index in 0..<testings.count {
testings[index].value = 15
}
in this case you are accessing (and modifying) the actual struct element and not a copy of it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…