Search code examples
arraysswiftintegerreverse

How to reverse a integer array in swift


How to reverse an integer array in swift

eg: var ab = [1,2,3,4]

I want to store the array in reverse format.

The result should be

ab = [4,3,2,1]

Solution

  • use ab.reversed() function which returns a reversed array.