Lesson 3

Introducing Swift

Prior to the launch of iOS8, Objective-C was the official language used to make native applications. With the launch of iOS 8, Apple provided an alternative language called Swift. Now it is possible to code iOS (and Mac OSX) applications in both Objective-C and Swift. This book targets Swift 2.0, which is supported on iOS 9 and later. This lesson introduces some of the basic concepts of Swift.

Introducing Xcode Playgrounds

Playgrounds are a new feature of Xcode (available from versions 6 and above) that allow you to rapidly prototype Swift code. You cannot create a complete app in a playground, but if you want to quickly try out an algorithm or just want to get a feel for the Swift programming language, then playgrounds are for you.

To create a playground, you can either select the Get started with a playground option in the Xcode welcome screen (Figure 3.1), or select the File arrow New arrow Playground menu item.

Screenshot of Xcode welcome screen with Get started with a playground option encircled.

Figure 3.1

Xcode will then ask you to provide a name for the playground as well as the platform. In this book, only iOS playgrounds are explored (Figure 3.2).

Figure 3.2

Xcode will then prompt you to provide a location where the playground ...

Get Swift iOS 24-Hour Trainer now with O’Reilly online learning.

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