Swift Object reference to array?

前端 未结 4 1186
面向向阳花
面向向阳花 2021-01-18 18:30

I probably missed an important information about swift. I have a map contains a key / swift array pair. I changed the array and the array inside the map was not changed. Cou

4条回答
  •  生来不讨喜
    2021-01-18 18:43

    As Code Different says, Arrays in Swift are structs, so you are storing a copy of the array.

    If you really want to keep using Swift arrays, I recommend to fill the array "list" first and then copy to "map". That should work for you.

提交回复
热议问题