How to exchange elements in swift array?

后端 未结 5 585
花落未央
花落未央 2021-02-06 22:15

I have one simple array like:

var cellOrder = [1,2,3,4]

I want to exchange elements like suppose a second element with first element.

A

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-06 22:55

    Use swapAt method,

    var arr = [10,20,30,40,50]
    arr.swapAt(2, 3)
    

    Use the index to swap element.

提交回复
热议问题