Q: Swift3 - Issue with extending type Collection Good day,
Im trying to understand protocols and extensions in Swift 3.
Im trying to extend Collection by a mutable functions to e.g. heal all enemies inside an Array of Type Enemy.
Here is an example GIST: https://gist.github.com/flowinho/5985928f803d902b75fc69ee9ce26537
Im still new to the field of adding mutable functions by extending protocols, so i dont understand why LOC 75 of that gist doesn't increase the amount of HP of all enemies.
What am i doing wrong?
How to fix this?
Best wishes and have wonderful day,
Flowinho

A: This is because struct is a value type and a copy is made when you assign it. Your code will work if you use classes instead of structs. Or you need to access the array elements by index:
for item in myStructArray {
    // changes copy of item, array is not altered
    item.property = newValue
}

for i in 0..<myStructArray.count {
    // this does what you need, changes the struct in the array
    myStructArray[i].property = newValue
}

