Weekly Swift articles, podcasts and tips by John Sundell.

Using zip

Published on 16 Jan 2018
Basics article available: Map, FlatMap and CompactMap

Using the zip function in Swift you can easily combine two sequences. Super useful when using two sequences to do some work, since zip takes care of all the bounds-checking.

func render(titles: [String]) {
    for (label, text) in zip(titleLabels, titles) {
        print(text)
        label.text = text
    }
}