A set stores unique values or elements as a collection in Swift. An empty set has no value in it. The isEmpty
method determines if a set is empty. It returns a Boolean.
set.isEmpty
There are no parameters.
The returning value of isEmpty
is Boolean. If the set is empty, true
is returned. Otherwise, false
is returned.
// create some setslet evenNumbers : Set = [2, 4, 6, 8, 10]let oddNumbers : Set = [3, 5, 7, 9, 11]let emptySet = Set<String>()// check if emptyprint(evenNumbers.isEmpty) // falseprint(oddNumbers.isEmpty) // falseprint(emptySet.isEmpty) // true
isEmpty
method to check if the sets we create are empty. The results are printed to the console.