Swap 2 elements in array

 Problem

I have an array and want to swap two of its elements, by index.



 Recipe


// Initialize the Array
var arr = ["one", "two", "three", "four", "five"]

// Swap elements at index: 2 and 3

swap(&arr[2], &arr[3])
print(arr)

				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground