A sequence of pairs built out of two underlying sequences.

    @frozen struct Zip2Sequence<Sequence1, Sequence2> where Sequence1 : Sequence, Sequence2 : Sequence

    In a Zip2Sequence instance, the elements of the ith pair are the ith elements of each underlying sequence. To create a Zip2Sequence instance, use the zip(_:_:) function.

    The following example uses the zip(_:_:) function to iterate over an array of strings and a countable range at the same time:

    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"

    Citizens in Swift

    where Sequence1:Sequence, Sequence2:Sequence




    Citizens in Swift

    where Sequence1:Sendable, Sequence1:Sequence, Sequence2:Sendable, Sequence2:Sequence


    • protocol Sendable

      A type whose values can safely be passed across concurrency domains by copying.