Creates a sequence of pairs built out of two underlying sequences.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
Parameters
sequence1
The first sequence or collection to zip.
sequence2
The second sequence or collection to zip.
Return Value
A sequence of tuple pairs, where the elements of each pair are corresponding elements of sequence1
and sequence2
.
Discussion
In the Zip2Sequence
instance returned by this function, the elements of the ith pair are the ith elements of each underlying sequence. The following example uses the zip(_:
function to iterate over an array of strings and a countable range at the same time:
If the two sequences passed to zip(_:
are different lengths, the resulting sequence is the same length as the shorter sequence. In this example, the resulting array is the same length as words
: