O'Reilly logo

iOS 9 SDK Development by Janie Clayton, Chris Adamson

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

Packaging Data in Collections

With numeric types and strings, one thing we’ll frequently want to do is to put them into collections. Nearly all languages have multiple ways of putting items into groups so we can then organize and perform operations on the entire group. Swift provides three main types of collections: arrays, sets, and dictionaries.

To start playing with these, start a new playground called CollectionsPlayground, and delete the line that creates the "Hello, playground!" string.

Arrays

For many of us, the most frequently used collection is the array. Arrays contain multiple items and maintain the ordering of those items. They also allow for the same item to appear multiple times in the array.

We’ll start with an array of strings ...

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