The Swift Programming Language Companion (3 Part Series)
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.
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.
- Open Xcode
- Choose File > New Playground ...
- Choose Blank
- Call it SwiftBook.playground
- Use CMD-1 to open the left sidebar to the Project Navigator. CMD-0 will hide/show this sidebar.
- Choose File > New Playground Page twice (so you have three pages)
- 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.
- Choose "01-The Basics" in the Project Navigator
It should look like this:
I have a 13" MacBook Pro, so this is kind of tight. Here's what it looks like for me.
There should be a line of code that looks like this
var str = "Hello, playground"
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)
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.
The next post will be a companion to the "The Basics". If you need any help setting up, comment below.