To sort an array in ascending order in Swift, you can use the `sort()` method.
In this example,
numbers
.sort()
method to sort the array in-place.var numbers = [5, 2, 8, 1, 9]
numbers.sort()
print("Sorted Array of Integers: \(numbers)")
Sorted Array of Integers: [1, 2, 5, 8, 9]
In this example,
words
.sort()
method to sort the array in-place based on string comparison.var words = ["apple", "banana", "cherry", "date"]
words.sort()
print("Sorted Array of Strings: \(words)")
Sorted Array of Strings: ["apple", "banana", "cherry", "date"]
In this tutorial, we learned How to Sort an Array in Ascending Order in Swift language with well detailed examples.