Swift Array – Remove All Elements
To remove all elements of an Array in Swift, call removeAll() method on the array.
The syntax to call
removeAll() method on the array is
where parameter is optional, and hence if we do not provide an condition, all the elements in the array are deleted.
In the following program, we will take an array
fruits with five elements, and remove all of its elements using
var fruits = ["apple", "banana", "cherry", "mango", "guava"] fruits.removeAll() print(fruits)
All the elements have been removed from the array, and an empty array is printed in the output.
In this Swift Tutorial, we learned how to remove all the elements from an array in Swift.