Swap array elements show error: Simultaneous acces

2020-04-08 10:50发布

问题:

I want to swap my array elements:

swap(&(self.profileImages[0]), &(self.profileImages[2]))

But I get this error:

Simultaneous accesses to 0x102944a80, but modification requires exclusive access

回答1:

After lots of searching: As Whats-new-in-Swift-4 describe I found that in swift4 I should use this code:

self.profileImages.swapAt(0, 2)