O'Reilly logo

Transitioning to Swift by Scott Gardner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter    5

Controlling Program Flow

Although there can be a multitude of ways in which to control program flow in code, often the best approach balances succinctness and readability with performance.

In this chapter, the similarities and differences of each control flow construct in Objective-C and Swift will be examined, and entirely new capabilities in Swift will be introduced.

Let’s begin by covering two new Swift mechanisms for creating representations of iterable sequences that can be used in control flow statements: range operators and stride() functions.

Range Operators

Objective-C includes NSRange, which is a struct representing the location and length index of a series of values. Although it can be used outright to iterate over a range ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required