To check if a Set is not empty in Swift, you can use the isEmpty
property.
In this example,
set
and initialize it with some elements.isEmpty
property on the Set set
to check if it contains any elements.isEmpty
property returns false
; otherwise, it returns true
.var set: Set<Int> = [1, 2, 3] // Or var set: Set<Int> = [] for an empty Set
if !set.isEmpty {
print("The Set is not empty")
} else {
print("The Set is empty")
}
The Set is not empty
In this example,
emptySet
.isEmpty
property on the Set emptySet
to check if it contains any elements.isEmpty
property returns true
.var emptySet: Set<Int> = []
if !emptySet.isEmpty {
print("The Set is not empty")
} else {
print("The Set is empty")
}
The Set is empty
In this tutorial, we learned How to check if a Set is Not Empty in Swift language with well detailed examples.