Xcode is Apple’s programming application for developers. It’s free from the Mac App Store, and it's required to do development for Apple’s platforms. So, your first action is to click here to install Xcode from the Mac App Store – it’s quite a big download, so start downloading it now and carry on reading.
While that's downloading, I can explain a couple of the absolute basics to you:
That’s it for the basics – if Xcode still hasn't finished downloading then why not watch some Taylor Swift videos while you wait? The examples in this tutorial will certainly make a lot more sense…
Got Xcode installed? OK! Let’s do this…
When you launch Xcode, you’ll see the Welcome to Xcode window where you can create a new project or open one of your recent projects. We don’t want a project for now, because we’ll be using a playground – little mini projects that let us run code quickly. You can make a new playground by going to the File menu and choosing New > Playground.
Xcode will ask you whether you want to create a playground for iOS or macOS, but it doesn’t matter here – this introduction is almost exclusively about the Swift language, with no user interface components. For the avoidance of problems, leave “iOS” selected for the platform. You’ll see a list of playground templates you can choose from, but we’re going to start small here so please choose Blank.
Finally, Xcode will ask you to name your playground – the default name of "MyPlayground" is fine, so go ahead and click Create.
What you'll see is a window split in two. On the left you'll see this:
import UIKit
var greeting = "Hello, playground"
And on the right, once Xcode has built and run the code, you’'ll see this: "Hello, playground". Note that build and running the code takes 10 seconds or so the first time, but is fast otherwise – Xcode has to launch a mini simulator behind the scenes.
This split is important, because it divides code and results. The code is in the left pane, and you will edit this to do your own Swift work as we go. The results are in the right pane, and it shows you what your Swift code has done. In this case, it’s telling us that we successfully set the value "Hello, playground."
Playgrounds run whatever code you write, one line at a time, and show the updated results in the side bar. To the left of each line of code you’ll see a blue bar, and if you hover over various lines there you’ll see you can press a play button to run the code up to that point.
Playgrounds are a great way to try some code and see the results quickly. They are extremely powerful too, as you’ll see over the next hour or so. Let’s get started writing Swift!
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Link copied to your pasteboard.