A hash is an integer value that is unique and used to represent other values such as a set, integer, arrays, strings, etc. In the Set
collection, two equal sets can have the same hash value. In order to get the hash value of a Set
class, we use the hashValue
property.
Note: Hash values are different for every execution.
set.hashValue
The value returned is a hash value, which is an integer.
// create some sets let evenNumbers1 : Set = [10, 2, 6, 8, 4] let evenNumbers2 : Set = [10, 2, 6, 8, 4] let oddNumbers : Set = [11, 5, 7, 3, 9] let first_names : Set = ["john", "jane", "henry", "mark"] // get the hash values print(evenNumbers1.hashValue) print(evenNumbers2.hashValue) print(oddNumbers.hashValue) print(first_names.hashValue)
Set
collection and initialize them with some elements.RELATED TAGS
CONTRIBUTOR
View all Courses