DEV Community

Lou Franco
Lou Franco

Posted on • Updated on • Originally published at app-o-mat.com

The Swift Programming Language Companion: Introduction

This is part of a series that will help guide you through reading The Swift Programming Language from Apple.

The intended audience for this guide are people that don't know Swift and possibly don't know any other programming language.

I wrote previously that the best way to get into iOS App development was to start with Swift, not an app tutorial. Apple's book is good enough to get started—this companion is meant to help you read it actively. By the time you are done with the book, you should have written a lot of Swift, not just read it.

Step 1: Set up a reading environment

You need to be able to see the book and an Xcode playground at the same time. That could be side-by-side on your Mac or you could read the book on an iPad.

Step 2: Set up an Xcode Playground

  1. Open Xcode
  2. Choose File > New Playground ...
  3. Choose Blank
  4. Call it SwiftBook.playground
  5. Use CMD-1 to open the left sidebar to the Project Navigator. CMD-0 will hide/show this sidebar.
  6. Choose File > New Playground Page twice (so you have three pages)
  7. Name the pages "01-The Basics", "02-Basic Operators", and "03-Strings and Characters". Note: Playgrounds auto-sort the pages by their name, so using the 00-Title format keeps the pages in the same order as the book.
  8. Choose "01-The Basics" in the Project Navigator

It should look like this:

Xcode sidebar showing playground pages

Step 3: Setup

I have a 13" MacBook Pro, so this is kind of tight. Here's what it looks like for me.

Side by side Xcode and Swift Book

Step 4: Test your Playground

There should be a line of code that looks like this

var str = "Hello, playground"
Enter fullscreen mode Exit fullscreen mode

Put your cursor at the end of that line and type SHIFT-ENTER. This will run the playground up until that line of code (note the playhead on the left -- you could also use the mouse and tap that)

Step 5: Read and Code

Read the book. Do not copy any code from the book into the playground—type it in yourself. Make sure you understand it before moving on.

After typing a line of code, you can type SHIFT-ENTER to run that line of code. The right side will show you the result.

What's next

The next post will be a companion to the "The Basics". If you need any help setting up, comment below.

Top comments (0)