swift & iOS/swift

[swift] 딕셔너리 요소 삭제하기

whale3 2022. 2. 7. 11:43

없애고 싶은 항목에 키에 nil을 할당하거나 removeValue 메소드를 사용하여 korKey라는 argument에 없애고 싶은 키를 전달하면 된다.

 

var myDict = ["one":1, "two":2]
myDict["two"] = nil
print(myDict)

myDict.removeValue(forKey: "one")
print(myDict)
반응형