- Swift iOS Programming for Kids
- Steffen D. Sommer Jim Campagno
- 552字
- 2021-07-09 19:04:56
Setting up our first Xcode playground
With the release of Xcode 6, Apple introduced a new feature, called playgrounds. A playground is lightweight compared to a traditional Xcode project and is a great tool to try out things in Swift without having to worry about setting up a complete project. We can use a playground to write our first program, which will not have any GUI.
Creating the playground
Start off by opening up the Xcode application we installed in Chapter 2, Getting Set Up. Look for the following icon in your applications folder:

The first thing you will see in Xcode is the Welcome to Xcode window, which will give you quick access to creating new projects and opening your recent ones:

A complete application that can be installed, for example, on an iPhone, requires some project files and configuration. This is not needed now, as we just want to write our first line of Swift code, therefore, we will only focus on playgrounds. We will get back to how to set up a complete Xcode project in a later chapter.
Go ahead and click on the Get started with a playground item from the menu. Note that if you closed the Welcome to Xcode window, or it never appears for some reason, you can always create a new playground from the menu bar by navigating to File | New | Playground..., as illustrated:

Now that we have created a new playground, let's move on to saving it.
Saving our playground
The next step is to enter a proper name for our new playground. We suggest typing in HelloWorld
as a name for this playground. Next, we will choose the platform to target, which has the following three options:
- iOS: This is the platform for developing iPhone and iPad applications
- macOS: This is the platform for developing applications running on a Mac computer (for example, MacBook Pro)
- tvOS: This is the platform for developing Apple TV applications (requires Apple TV 4th generation or a later version at the time of writing)
A platform refers to the devices that should be able to run our application. As mentioned in Chapter 1, What is Programming, decisions on what programming language to use and what device to target are what set the boundaries in terms of the available functionality for our application:

After filling out the form and clicking on Next, a save dialog will appear. Go ahead and choose where to store your playground file:

Ensure that you remember where you save it so that you can always open it again if you want to continue exploring Swift in the playground. If you delete it, however, a new playground can always be created.
Removing what is unnecessary
Now we are getting really close to having our playground set up. Once you select where to save the playground file, the playground will automatically open, as illustrated:

Don't worry about the content for now, as we won't be needing it. In fact, go ahead and remove all the text from the editor so that your playground is completely empty, as shown:

With our clean slate in place we are now ready to write our first lines of Swift code.
- Apache ZooKeeper Essentials
- Cocos2d-x游戲開發:手把手教你Lua語言的編程方法
- 架構不再難(全5冊)
- C# 從入門到項目實踐(超值版)
- Python從入門到精通(精粹版)
- HBase從入門到實戰
- Clojure for Domain:specific Languages
- Unity Shader入門精要
- SAP BusinessObjects Dashboards 4.1 Cookbook
- OpenCV 4計算機視覺項目實戰(原書第2版)
- 深入淺出React和Redux
- Python Programming for Arduino
- JavaScript前端開發基礎教程
- Hadoop Blueprints
- Java核心技術速學版(第3版)