Chapter 3. Diving into Swift

In this chapter, you will learn the basics of Swift, Apple’s new programming language. You will learn about creating variables, collections, loops, and conditions in Swift. These items are used in 99% of apps. This chapter will teach you the most important pieces of the Swift language, so you can start building apps fast.

What Is Swift?

Swift is a new programming language created by Apple as the language of their future. Swift was originally announced during the Apple Worldwide Developer Conference in June of 2014. Apple had used Objective-C, originally created for the Mac, for over 20 years. Swift was created to make writing code easier and more concise. Swift is perfect for beginners and has lowered the barriers so that anyone can make apps.


One of Swift’s most exciting new features are playgrounds. Playgrounds are a quick and simple way to write your code and test it immediately. I highly recommend that you keep a playground file open next to you while you read this book. Follow along and write out each line of example code provided. Writing out the code will not only help you see how it works, but it will also improve your muscle memory. Open up a new playground file now (Figure 3-1).

New file
Figure 3-1. New file

Open Xcode and Select File→New→File. Click Source under iOS. Next, click Playground and finally click Next (Figure 3-2).

Figure 3-2. Select ...

Get Introducing iOS 8 now with the O’Reilly learning platform.

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