Chapter 7

Collecting Objects

In This Chapter

arrow Working with mutable and immutable collections

arrow Starting with arrays

arrow Storing data in dictionaries

It’s often convenient to be able to group objects into collections so that you can handle them together. Whether you’re talking about students in a class, items in a desk drawer, or values in an array, collecting items together makes your code easier to read (and write!).

Swift has two types of collections: arrays and dictionaries. Arrays are the standard indexed collections of values that can be accessed by their index. Dictionaries are associative arrays in which the values are accessed by a key value and a hash routine.

As is true in most languages that support arrays and dictionaries (or associative arrays), the syntax for manipulating these collections and their data values is different for the two forms of collections. Associative arrays are usually thought to be a specific type of array rather than a separate concept altogether. For most programming languages, including Swift, the indexes for arrays are integers. Associative arrays, ...

Get Swift For Dummies now with the O’Reilly learning platform.

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