Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. SwiftBeginner - Setting Up the Swift Environment

Setting Up the Swift Environment - Images: Japanese

Hey there, everyone!

Let's continue by getting your Swift programming environment set up.

Before writing any code, you'll generally need to go through what's called environment setup — basically, getting everything in place so your code can actually run.

This applies to pretty much every programming language, not just Swift, so keep the term environment setup in mind. You'll hear it a lot in the real world.

So first things first — you'll need a relatively recent Mac in front of you.

The reason: as of right now (2016), the only officially supported development environment for Swift is Xcode (pronounced "ex-code") — an SDK (a toolkit built specifically for development) provided by Apple. There's really no other option at the moment.

Swift is open source, so it can technically run on Linux and similar systems — but from the author's experience, it was still a bit unstable and the installation was pretty involved, so it's not something easy to recommend for those just getting started.

Besides, Swift is currently used almost exclusively for building iPhone apps and the like, so if you're learning Swift to actually ship something or get results, you'd need a Mac either way.

Apple also tends to drop support for older devices fairly quickly, which means older versions of macOS may not be able to install the latest macOS or Xcode.

That leads to situations where you can't use the latest Swift syntax, or your builds (the process of turning source code into a runnable app) just won't go through — which makes development pretty painful.

That's why you need a relatively recent Mac.

Mac computers do tend to cost a bit more than Windows PCs...

That's probably the biggest obstacle for a lot of people.

If budget is tight, there are some browser-based services that let you try out Swift, so that might be worth exploring. You can probably cover the basics through one of those.

Alright, from here on we'll assume you have a Mac in front of you and carry on.

Open your Mac and launch the app called App Store. This one here.

This is the official app for purchasing and installing Mac applications — familiar territory if you're a Mac user.

Type xcode in the search bar and it should show up. Go ahead and install it. Xcode is free.

One heads-up about the installation: Xcode is enormous (around 4GB). If you're on a tethered mobile connection out and about, you'll probably want to wait until you get home. You'd almost certainly hit your data cap.

And it's not just the download — the installation takes a while too, so grab a coffee, queue up some cute cat videos, and settle in for the wait.

Once the installation is done, go ahead and open Xcode. You should see a screen like the one below. Click where the arrow points — that's Get started with a playground.

A screen will pop up asking you to choose a Name and Platform. Either is fine — it'll probably default to MyPlayground for the name and iOS for the platform. Unless you have a preference, just leave them as-is and click Next.

The next screen asks where you want to save the file. Anywhere is fine — Desktop or Documents are both perfectly good choices. Click Create to save.

Once saved, the editor should open right up. But before we jump into writing code, head over to the folder you just selected. You should find a file named something like MyPlayground.playground.

This is the Xcode playground file. Next time you want to open it, just double-click this file. The .playground extension is worth remembering — that's what Xcode uses for playground files.

※ For more details on file extensions, see this article.

By the way, playground literally means a place to play — and that's exactly what it is in Xcode: a sandbox environment set up for learning and trying out code snippets.

We'll be using this playground throughout this course, so make sure you've got the hang of how to create (start) and open one.

One more thing to note: Xcode is entirely in English. That might be a bit of a challenge if you're not comfortable with the language, but push through — you've got this.

Xcode updates very frequently, making it extremely difficult to maintain a localization patch.

A Japanese localization is unlikely to be released going forward.

Now, let's take another look at the editor that opened. There may be slight differences depending on your version and setup, but it should look something like this.

If everything opened correctly, your environment is all set. Nice work! From here, you can start typing Swift into this editor and it should run right away.

If you're still feeling a little uncertain, don't worry — in the next article we'll write some simple code using print() and verify that everything is working. You're good to keep going as-is.

That's it for this one. See you in the next article!

This article was written by Sakurama.

Author's beloved small mammal

桜舞 春人 Sakurama Haruto

A Tokyo-based programmer who has been creating various content since the ISDN era, with a bit of concern about his hair. A true long sleeper who generally feels unwell without at least 10 hours of sleep. His dream is to live a life where he can sleep as much as he wants. Loves games, sports, and music. Please share some hair with him.

If you find any errors or copyright issues, please .