없애고 싶은 항목에 키에 nil을 할당하거나 removeValue 메소드를 사용하여 korKey라는 argument에 없애고 싶은 키를 전달하면 된다.
var myDict = ["one":1, "two":2]
myDict["two"] = nil
print(myDict)
myDict.removeValue(forKey: "one")
print(myDict)
반응형
'swift & iOS > swift' 카테고리의 다른 글
[swift] 딕셔너리의 key, value를 배열로 만들기 (0) | 2022.02.07 |
---|---|
[swift] 딕셔너리에 for...in 으로 접근하기 (0) | 2022.02.07 |
[swift] 빈 딕셔너리 dictionary 선언하기 (0) | 2022.02.07 |
[swift] reduce (0) | 2022.02.04 |
[swift] 배열에서 nil 이 아닌 값만 추려내기 (compactMap) (0) | 2022.02.04 |