Q:

How do I sort an array of (Int, String) by Int value?

var array = [(Int, String)]()

I need the pairs in the array sorted in ascending order by the value of the Int.
array = [(2, "is"), (0, "Hello"), (1, "this"), (3, "Ben")]

I need this to return:
array = [(0, "Hello"), (1, "this"), (2, "is"), (3, "Ben")]

I think some variation of the following should work, but I can't figure out how to set it up.
array.sortInPlace()

A:

let array = [(2, "is"), (0, "Hello"), (1, "this"), (3, "Ben")]
let sortedArray = array.sort { $0.0 < $1.0 }

print(sortedArray) // [(0, "Hello"), (1, "this"), (2, "is"), (3, "Ben")]

The .0 part represents the first object of the tuple.
See Matt's answer for the mutable version.

