Chapter 3. Collecting and Controlling: Going Loopy for Data
You already know about expressions, operators, variables, constants, and types in Swift. It’s time to consolidate and build on that knowledge and explore some more advanced Swift data structures and operators: collections and control flow. In this chapter, we’re going to talk about putting collections of data into variables and constants, and how to structure data, manipulate data, and operate on data using control flow statements. We’ll be looking at other ways to collect and structure data later in the book, but for now let’s get started with arrays, sets, and dictionaries.
Meet the Swift Pizzeria, the fastest pizza place in town.
Get it? Hilarious.
The Chef, who is pretty grumpy at the best of times, wants to sort the restaurant’s pizzas alphabetically using Swift (after all, it’s in the name).
They’re facing some issues, though. Can you help the chef sort their pizzas?
Swift has a range of special types that can store collections of things. Unsurprisingly, these are called collection ...