Basic Swift

So, let's get going with a rapid rundown of Swift's basic types and syntax. As befits a book aimed at developers with some experience of programming under their belts, this chapter will not be about the basics of programming, but simply an overview of what we will assume you know as we move through the following chapters. Think of it as a kind of Swift comments cheat-sheet, if you like.

You already understand something of variable declaration, control flow, arrays and dictionaries, and functions. Make sure you fully understand everything that is presented in this chapter, and if there are any concepts you don't understand by the end of it, it's probably a good idea to delve into them somewhat before moving on to Chapter 5, Advanced Swift.

I have tried in this chapter to flag a few typical gotchas that occur when coming from other languages or earlier versions of Swift. Some of the terms used in Swift are used in other languages with a different meaning, and some concepts behave differently.

If Swift is the only language you have used, and you have used it often, you might want to skip this chapter. But you'll miss all of the wit and enlightening commentary if you do.

This chapter, and indeed the whole book, does not try to provide an exhaustive documentation of the Swift language. It's a good idea (sooner or later) to have read Apple's eBook, The Swift Programming Language. This is available for free in iBooks.

By the time we reach the end of this chapter, you should have a basic but solid understanding of the following topics:

  • Swift's simple data types
  • Array, dictionaries, and sets
  • Value and reference types
  • Operators
  • Structs, classes, and other data structures
  • Optionals, and why they are important
  • Control-flow statements
  • Defining and calling functions