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 |
Tags
- 프로그래머스
- 티스토리챌린지
- java
- 플러터
- 영화기록
- 키노
- 자바
- 영화리뷰
- 오블완
- sopt ios
- toy project
- 스프링 입문
- SWIFT
- 일기
- Flutter
- 영화일기
- 백준
- inflearn
- SOPT
- 자바공부
- sopt 35기
- 코딩공부
- 자바 스터디
- 영화후기
- 토이프로젝트
- 인프런
- 영화
- 리뷰
- Flutter Toy Project
- 새벽녘 소소한 기록
Archives
- Today
- Total
새벽의 기록
[ios\swift] 내장함수 zip(_:_:) 본문
두 개의 시퀀스를 조합하여 새로운 하나의 시퀀스를 생성하는 함수
https://developer.apple.com/documentation/swift/zip(_:_:)
zip(_:_:) | Apple Developer Documentation
Creates a sequence of pairs built out of two underlying sequences.
developer.apple.com
두 개의 시퀀스를 조합하여 새로운 하나의 시퀀스를 생성하는 함수
# case1
let words = ["one", "two", "three", "four"]
let numbers = 1...4
for (word, number) in zip(words, numbers) {
print("\(word): \(number)")
}
// Prints "one: 1"
// Prints "two: 2"
// Prints "three: 3"
// Prints "four: 4"
# case2
let names = ["Alice", "Bob", "Charlie"]
let ages = [25, 30, 28]
for (name, age) in zip(names,ages) {
print("\(name) is \(age) years old")
}
// prints "Alice is 25 years old"
// prints "Bob is 30 years old"
// prints "Charlie is 28 years old"
문자열 관련 문제 풀 때 자주 쓰일 것 같다
# case3
let items = ["book", "pen", "coffee"]
let prices = [10000, 3000, 2800, 5000]
for (item, price) in zip(items,prices) {
print("\(item) : \(price)원")
}
// prints "book : 10000원"
// prints "pen : 3000원"
// prints "coffee : 2800원"
두 시퀀스의 길이가 다를 경우에는 짧은 쪽에 맞춰진다
'[iOS]' 카테고리의 다른 글
delegate extension, datasource extension 뭐가 뭐지? (0) | 2024.11.22 |
---|---|
[ios\swift] SwiftUI TextField 글자 수 제한 (0) | 2024.08.06 |
[ios\swift] 고차함수 (map, filter, reduce) (0) | 2024.06.11 |
[ios\swift] allSatisfy(_:) (0) | 2024.06.10 |
Comments