What is the string.hashValue property in Swift?
Overview
In Swift, hashValue is a string property, used to return the hash value of a string value.
Syntax
string.hashValue
Return value
It returns the hash value of string.
Example
// create some stringslet name = "Theodore"let language = "Swift"let emptyString = ""// get hashValue propertylet debugDesc1 = name.hashValuelet debugDesc2 = language.hashValuelet debugDesc3 = emptyString.hashValue// print resultsprint(debugDesc1) // "Theodore"print(debugDesc2) // "Swift"print(debugDesc3) // ""
Explanation
- Lines 2–4: We create three
stringvalues. - Lines 7–9: We use the
hashValueproperty to get the hash values of the strings, and save the results. - Lines 12–14: We print the results to the console.