Sort array in ascending order

 Problem

I have an Array and want to sort its contents (numeric or lexicographically) in ascending order.



 Recipe


// Initialize the Array
var a = [6,3,2,1,5,4]

// Sort (ascending) its elements

a = a.sort { $0 < $1 }
print(a)
				

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