- Mastering macOS Programming
- Stuart Grimshaw
- 46字
- 2021-07-02 22:54:40
Sorting arrays
The sort methods available on arrays come in two flavors:
The sorted method returns a new, sorted array:
var randomInts = [233, 6, 85, 1, 6, 24]
let sortedInt = randomInts.sorted()
print(randomInts) //unchanged
The sort method mutates the array in place:
randomInts.sort()
print(randomInts) //mutated