Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

Swift Use of Hash Function

struct Employee: Hashable {
  
 var name: String
 var salary: Int

 // create a hash() function to only compare  age property        
 func hash(into hasher: inout Hasher) {
   hasher.combine(salary)
 }

}

// initialize two objects with different values for salary property
let obj1 = Employee(name: "Sabby", salary: 349879)
let obj2 = Employee(name: "Sabby", salary: 422532)

print(obj1.hashValue)
print(obj2.hashValue)
Comment

PREVIOUS NEXT
Code Example
Swift :: how to add dragdown gesture recognizer on view 
Swift :: swift array in chunks 
Swift :: Swift Add Two Numbers 
Swift :: swift sf symbol uiimage size 
Swift :: swift apply changes after a word in string 
Swift :: Working of Recursion in Swift 
Swift :: Log httpurlresponse swift 
Swift :: UIApplicationWillEnterForeground 
Swift :: swift increase int value 
Swift :: ios tableview hide empty cells 
Swift :: Swift Equatable Protocol 
Swift :: xcode button center text 
Swift :: Why Inheritance? 
Swift :: Autoclosure Swift 
Swift :: helen joseph 
Swift :: uilabel font size and bold 
Swift :: swift closures 
Swift :: How to Hide Password in Text field Swift 
Swift :: Type Constraints in Swift Generics 
Swift :: swiftUI parse json from url 
Swift :: didselectrowatindexpath not called swift 
Ruby :: rails delete child on parent delete 
Ruby :: rspec check array without order 
Ruby :: ruby constructor 
Ruby :: rails disable cache on dev 
Ruby :: rails check_box_tag 
Ruby :: ruby check if value in array 
Ruby :: ruby boolean variable 
Ruby :: increment in ruby 
Ruby :: ruby create engine using rspec and dummy 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =