Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Xcode
- 리펙토링
- UITextView
- ios
- clean architecture
- RxCocoa
- collectionview
- ribs
- Clean Code
- swift documentation
- Observable
- Human interface guide
- 리팩토링
- HIG
- scrollview
- UICollectionView
- Protocol
- 스위프트
- map
- 애니메이션
- uitableview
- 클린 코드
- uiscrollview
- Refactoring
- combine
- SWIFT
- swiftUI
- MVVM
- tableView
- rxswift
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] dictionary nil 초기화 시 주의사항 본문
Dictionary 초기화 시 주의사항
- dictionary: key - value 쌍으로 데이터를 저장할 수 있는 형태
- dictionary 값을 초기화하는 방법에 대해서 명확히 알고 있어야 사용할때 혼동이 생기지 않음
초기화 방법
- key-value 모두 날리고 싶은 경우
- dictinoary 대괄호 안에 key값을 넣고, 오른쪽에 nil을 대입
var dict: [Int: String?] = [1: "1", 2: "2", 3: "3"]
dict[1] = nil
// [2: Optional("2"), 3: Optional("3")]
or removeValue(forKey:) 사용
var dict: [Int: String?] = [1: "1", 2: "2", 3: "3"]
dict.removeValue(forKey: 1)
// [2: Optional("2"), 3: Optional("3")]
- key값은 삭제하지 않고, value 값만 nil로 바꾸고 싶은 경우
- updateValue(nil, forKey:) 사용
dict.updateValue(nil, forKey: 2)
print(dict)
// [2: nil, 3: Optional("3")]
'iOS 응용 (swift)' 카테고리의 다른 글
[iOS - swift] 2. memgraph 메모리 프로파일링 - vmmap을 사용하여 문제가 있는 코드의 메모리 주소 찾아내기 (0) | 2023.12.25 |
---|---|
[iOS - swift] 1. memgraph 메모리 프로파일링 - 샘플 준비 (1) | 2023.12.24 |
[iOS - swift] UIPinchGestureRecognizer 개념 (줌 기능, zoom) (3) | 2023.12.22 |
[iOS - swift] LazySequence 개념 (배열 데이터 다룰때의 최적화) (0) | 2023.12.20 |
[iOS - swift] 메모리 프로파일링 - 맛보기 (메모리 관점에서의 UIImage 관리, 이미지 처리) (16) | 2023.12.19 |