Selecting Sequences and Strides

Swift offers several built-in approaches to numeric progressions. These include ranges, stride functions, and sequence functions. Select your solution based on the progression you’ll produce. The latest versions of Swift provide excellent tools for establishing sequences.

In particular, Swift has eliminated many of the issues that previously detracted from floating-point strides. Strides no longer introduce cumulative errors during their execution the way traditional C for loops did. When choosing between stride and sequence, base your selection on utility, not accuracy concerns.

Prefixing

Swift 3.1 adds more flexibility and power by introducing prefix(while:) and drop(while:) as native operations on sequences. ...

Get Swift Style, 1st Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.