Chapter 2. Introduction to Swift playgrounds

 

This chapter covers

  • Exploring Xcode playgrounds
  • Using type safety in Swift
  • Understanding simple Swift data types
  • Working with collections and tuples in Swift
  • Working with optionals

Swift isn’t JavaScript without the semicolons or Objective-C without the square brackets. Swift is inspired by new philosophies and approaches to programming that have driven its design and evolution.

Even the most experienced programmers will encounter new concepts and syntax in Swift. In this chapter and the next, I assume that you have experience in programming and are mainly interested in what’s new, different, and exciting about Swift. I’ll also discuss how concepts in Swift relate to shifts in programming philosophy.

After looking at data types and collection types in Swift, we’ll look at a type that may be new to many: the optional. The optional, tied closely to the idea of type safety in Swift, can be unfamiliar at first, but do stick with it—the optional is essential to understanding programming in Swift.

There’s much to look at in Swift, but don’t worry; as you progress in the book, or for those of you who may already have some experience with Swift, you can always refer to the cheat sheets in appendix B. This chapter is summarized in the first two pages of the cheat sheets.

2.1. Xcode playground

2.2. Type safety and type inference

2.3. Collections

2.4. Control Flow

2.5. Functions

2.6. Optionals

2.7. Tuples

2.8. Higher-order functions

2.9. Summary

sitemap