Swift Integer Array – Sort in Increasing Order

To sort an integer array in increasing order in Swift, call sort() method on this array. sort() method sorts this array in place, and by default, in ascending order.

Example

In the following program, we will take an array of integers and sort them in increasing order using sort() method.

main.swift

var arr = [2, 8, 1, 9, 4, 7]
arr.sort()
print(arr)

Output

Swift Integer Array - Sort in Increasing Order
ADVERTISEMENT

Conclusion

In this Swift Tutorial, we learned how to sort an Integer Array in increasing order using sort() method.