Introducing the Swift Development Environment
Since the introduction of the iPhone in 2007, Apple seems to have lit a fire in the industry for not only consumer-based electronics but also the opportunity for most anyone to be able to write apps for their platform, be it Mac or iOS. This has had a dramatic effect on culture, as you cannot go to a coffee shop or to any business now and not see a slew of MacBook Airs, MacBook Pros, iPhones, and iPads. Chances are, if you’re reading this book, you are wondering how you can write an app that could appear on the screens of the very people you see at those coffee shops and businesses.
This book is about the Swift programming language, the new programming language announced by Apple at the 2014 World Wide Developer Conference (WWDC). Prior to Swift’s introduction, Mac and iOS apps were mainly written in a language called Objective-C, which is a strict superset of the C programming language, meaning that you could write apps in both languages, and sometimes had to. In this book we explore the Swift programming language and learn its fundamentals, structure, and syntax, which gives you a foundation to write great Mac and iOS apps.
What Is Swift?
Swift is a programming language customized by Apple and introduced as Objective-C without the C. Indeed, this is true, but Swift has also taken cues from other languages such as Haskell, Ruby, Python, C#, and several others. Swift is tuned to work with the existing Cocoa and Cocoa Touch frameworks, which contain all the familiar classes used in modern Mac and iOS apps, to support their interoperability.
Swift is built on three pillars: being safe, powerful, and modern. Swift provides a lot of safety in terms of type checking, constants for immutability, requiring values to be initialized before use, built-in overflow handling, and automatic memory management. With respect to power, Swift was built using the highly optimized LLVM compiler, includes many low-level C-like functions such as primitive types and flow control, and of course was built with Apple’s hardware in mind for optimal performance. Swift is also modern in that it adopted many features from other languages to make the language more concise yet expressive, such as closures, generics, tuples, functional programming patterns, and more that we cover in later hours.