Bibi's DevLog π€π
[Swift] .zip(_:_:) : λ μνμ€ ν©μΉκΈ° λ³Έλ¬Έ
π±π iOS/π Apple Developer Documentation
[Swift] .zip(_:_:) : λ μνμ€ ν©μΉκΈ°
λΉλΉ bibi 2022. 6. 21. 23:22[Swift] .zip(_:_:)
: λ μνμ€ ν©μΉκΈ°
λ μνμ€λ‘λΆν° λ§λ μνμ€ μμ λ§λλ λ©μλ
func zip<Sequence1, Sequence2>(
_ sequence1: Sequence1,
_ sequence2: Sequence2
) -> Zip2Sequence<Sequence1, Sequence2> where Sequence1 : Sequence, Sequence2 : Sequence
리ν΄κ°
- νν μμ μνμ€λ₯Ό 리ν΄νλ€.
- κ° μμ μνμ€1κ³Ό μνμ€2μ μμλ€μ μμνλ€.
νλΌλ―Έν°
- μνμ€1, 2 : κ°κ° zipν 첫 λ²μ§Έ, λ λ²μ¨° μνμ€ λλ 컬λ μ
μμλ₯Ό μ§μ μ¬μ©νλ €λ©΄
element.0
,element.1
μ²λΌ μ¬μ©ν μ μμ§λ§, ννλ‘ κ° μνμ€λ₯Ό μ΄λ¦λΆμ¬μ μ¬μ©νλ κ² λ νΈνλ€λ§μ½ λ μνμ€μ κΈΈμ΄κ° λ€λ₯΄λ©΄, 짧μ μͺ½μ μνμ€ κΈΈμ΄μ λ§μΆμ΄ zipμ΄ μμ±λλ€.
μμ μ½λ
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"