Chapter 2. Programming with Swift

The Swift programming language is a new language for writing software for both iOS and OS X. Introduced in June 2014 at Apple’s Worldwide Developers Conference (WWDC), Swift was a surprise to everyone: Apple had managed to develop an entire language (as well as all of the supporting libraries, developer tools, and documentation), and made it work seamlessly with the existing Objective-C language. And on top of that, it’s a really good language.

Swift draws upon an extensive history of language design, and has a number of very cool design features that make developing software easier, simpler, and safer.

In this chapter, you’ll learn how to code in Swift.

The Swift Programming Language

The Swift programming language aims for the following goals:

Safety
Swift is designed to be a safe language. Many of the pitfalls of C, such as accidentally working with null pointers, are much harder to encounter. Swift is very strongly typed, and objects aren’t allowed to be null except under very specific circumstances.
Modernity
Swift contains a large number of modern language features designed to make it easy to express the logic of your code. These include features like pattern-matching switch statements (see Switches), closures (Closures), and the concept of all values being objects that you can attach properties and functions to (Extensions).
Power
Swift has access to the entire Objective-C runtime, and is seamlessly bridged to Objective-C’s classes. This ...

Get Swift Development with Cocoa now with O’Reilly online learning.

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