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 ...
Get iOS 9 SDK Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.