Swift String Array – Sort Lexicographically

To sort a String Array lexicographically in Swift, call sort() method on this array. sort() method by default sorts a string array in place.

Example

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

main.swift

var arr = ["mno", "abc", "xyz", "pqr"]
arr.sort()
print(arr)

Output

Swift String Array - Sort in Lexicographical Order
ADVERTISEMENT

Conclusion

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