일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- TCA
- MVVM
- 프로그래머스
- swift
- ios
- BFS
- arkit
- reactorkit
- rxcocoa
- 백준
- designpattern
- node.js
- visionOS
- Xcode
- UIKit
- raywenderlich
- SwiftUI
- Flutter
- Kuring
- RxSwift
- Swfit
- SnapKit
- combine
- Lv2
- CollectionView
- XCTest
- realm
- tableView
- BOJ
- 패스트캠퍼스
Archives
- Today
- Total
lgvv98
[Swift5] 딕셔너리 contains 활용법 본문
✅ 딕셔너리 contains를 사용해보자!
var clothes = [["yellowhat", "headgear"], ["bluesunglasses", "eyewear"], ["green_turban", "headgear"]]
var category = [String:Int]()
//print(type(of: category))
for i in clothes {
if category.contains(where: { (key,value) -> Bool in
// 조건 검사
return key == i[1]
}) {
// if 문에 걸림 조건이 만족하면 실행된다.
//print(category[i[1]]! + 1)
category[i[1]]! += 1
//print("contains ok \(i)")
} else {
//print("not ok \(i)")
category[i[1]] = 1
}
}
'코딩테스트 > 🧸 Swift 문법' 카테고리의 다른 글
[Swift] 10진수를 2진수로 바꾸는 방법 (0) | 2022.03.19 |
---|---|
[iOS/Swift] init과 super.init에 대해서 알아보자. 🤔 (0) | 2022.02.25 |
[Swift5] extension Protocol (feat. optional func, objc) (0) | 2022.01.31 |
[문법] swift remove element from array by value (0) | 2021.11.17 |
[Swift5] 2차원 배열 정렬하기 문법 tip! (0) | 2021.11.16 |
Comments