let emptyDictionary : [String : Int] = [String : Int]()
let emptyDictionary : [String : Int] = [:]
let emptyDictionary = [String : Int]()
let emptyDictionary : [String : Int] = Dictionary<String, Int>()
var myFriends = ["bestFriend" : "쩡대리",
"highschool" : "영희"
]
let youtubeFriend = myFriends["youtube", default: "친구없음"]
myFriends["bestFriend"] = "개발하는 정대리"
//updateValue(값, forKey: 키)
myFriends.updataeValue("수잔", forKey: "girlFriend")
myFriends.count
for item in myFriends{
print("item: \(item)")
}
출력: item: (key: "", value: "")
dict["Apple"] = nil
은 해당 페어를 완전히 삭제하는 것이다.
[String: String?]에서 값을 nil로 하고 싶다면 서브스크립트 문법으로 불가능하다.
이 때는 dict.updateValue(nil, forKey: "Melon")
식으로 해주어야 한다.