Mobile/Swift

Dictionary

꼰대코더 2024. 2. 7. 23:44

미리 선언하기 ( key : value ) 

let employee = ["name": "Michael Jackson", "job": "Singer", "location": "LA"]

 

키로 값 가져오기

 print( employee["name"] )

 

선언하고 나중에 설정

var heights = [String: Int]() 

heights["Yao Ming"] = 229 
heights["Shaquille O'Neal"] = 216 
heights["LeBron James"] = 206 

 

값 변경

heights["Yao Ming"] = 150