Reference Materials
Certification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Swift Set removeAll()
In this tutorial, we will learn about the Swift set removeAll() method with the help of examples.
The removeAll() method removes all the elements from the set.
Example
var numbers: Set = [2,4,6,8]
// remove all elements
numbers.removeAll()
print(numbers)
// Output: []
removeAll() Syntax
The syntax of the removeAll() method is:
set.removeAll()
Here, set is an object of the Set class.
removeAll() Parameters
The removeAll() method doesn't take any parameter.
removeAll() Return Value
The removeAll() method doesn't return any value. It only removes elements from the set.
Example: Swift Set removeAll()
var languages: Set = ["Swift","Java","C"]
print("Programming Languages:", languages)
// removing all elements from set
languages.removeAll()
print("Set after removeAll:", languages)
Output
Programming Languages: ["Java", "Swift", "C"] Set after removeAll: []
Did you find this article helpful?