A set is a collection of unique elements. The length of a set is the number of elements present in that set. We can get the length of a set by using the count
property.
set.count
The value returned is an integer representing the number of elements a set instance contains.
// create some setslet evenNumbers : Set = [2, 4, 6, 8, 10, 12]let oddNumbers : Set = [3, 5, 7, 9]let emptySet = Set<String>()// get their lengthprint(evenNumbers.count)print(oddNumbers.count)print(emptySet.count)
count
property. Then, we print the results to the console.