Swift - How to mutate a struct object when iterating over it

前端 未结 5 861
清歌不尽
清歌不尽 2020-12-06 04:04

I am still not sure about the rules of struct copy or reference.

I want to mutate a struct object while iterating on it from an array: For instance in this case I wo

5条回答
  •  悲哀的现实
    2020-12-06 04:28

    You can use use Array.indices:

    for index in arrayOfMyStruct.indices {
        arrayOfMyStruct[index].backgroundColor = UIColor.red
    }
    

提交回复
热议问题