To check if a Set is empty in Swift, you can use the isEmpty property or the count property.
In this example,
// Define set
var mySet: Set<String> = []
// Check if set is empty using isEmpty property
if mySet.isEmpty {
print("Set is empty")
} else {
print("Set is not empty")
}
Set is empty
In this example,
// Define set
var mySet: Set<String> = []
// Check if set is empty using count property
if mySet.count == 0 {
print("Set is empty")
} else {
print("Set is not empty")
}
Set is empty
In this tutorial, we learned How to check if a Set is Empty in Swift language with well detailed examples.