© Radoslava Leseva Adams and Hristo Lesev 2016

Radoslava Leseva Adams and Hristo Lesev, Migrating to Swift from Flash and ActionScript, 10.1007/978-1-4842-1666-8_1

1. Setting Up Your Environment

Radoslava Leseva Adams and Hristo Lesev2

(1)London, UK

(2)Kazanlak, Bulgaria

Electronic supplementary material

The online version of this chapter (doi:10.​1007/​978-1-4842-1666-8_​1) contains supplementary material, which is available to authorized users.

Imagine a craftsman’s workbench with tools nicely laid out and labeled, a cup of steaming coffee at one end . . . ideally the kind of image that gives you an itch to start a fresh project you can pour your heart into. This chapter is all about setting up that workbench by sourcing, installing, and configuring the tools that you will need for native iOS development.

In this chapter you will do the following:

  • Learn about what Xcode can offer you as an iOS developer.

  • Download and install Xcode.

  • Set up Xcode for use with your Apple ID.

When you are done, you will have a fully set up IDE for developing iOS applications with Swift.

What Is Xcode?

Xcode is an integrated development environment (IDE) . It is free and is developed by Apple. With it comes the development toolset for making apps for Apple devices: Mac, iPhone, iPod, iPad, Apple Watch, Apple TV.

Xcode provides the usual features you would expect from an IDE and more. If you have developed iOS applications with AIR, you will find that Xcode improves and speeds up your workflow considerably. It offers all the tools you will need along the way: from rapid prototyping using Swift Playgrounds, through managing devices and debugging your app on them, to automated testing and even submitting your finished app to Apple’s App Store. Xcode’s profiling instruments could have a whole new book dedicated to them and will leave no doubt about your apps’ performance by measuring speed, memory, energy and network usage, GPU and CPU utilization, file activity and lots more.

Before You Begin

To download, install, and run Xcode you will need the following:

  • An Apple ID. If you don’t have one, you can register at https://appleid.apple.com/account . This ID identifies you as an Apple user, just like an Adobe ID identifies you as an Adobe user. It will stand you in good stead for developing and testing simple apps and you won’t need to enroll in any paid development program until you decide to use advanced SDK features or to publish your apps in the App Store—more on that in Chapter 2 .

  • A Mac computer. At the time of this writing Xcode 7.3 is the current release and requires that you run OS X 10.11 or later.

  • At least 10 GB of free space on your hard disk.

Step 1: Download Xcode

You have several choices for how to get Xcode, depending on whether you want an official release or a pre-release version. When new versions of Apple software are made available, they typically go through three stages: beta, seed, and official release. The main differences between versions in different stages are how stable they are, who can use a given version, and whether it can be used to build apps for release in Apple’s App Store.

  • Beta. This is a pre-release version, which is still under development and is available for download to anyone who has an Apple ID. Using a beta version puts you ahead of changes, as it allows you to update and test your apps with the latest tools and SDKs before they are officially available. There are a couple of drawbacks, however. Although they are close to the final thing, beta versions are by definition not as polished as official releases, so you may encounter bugs or inconsistencies. Another drawback is that apps that were built using beta tools are not accepted in Apple’s App Store: to be able to release your app in the store, you will need to use either an official Xcode and iOS SDK release or a GM seed (see the next bullet).

  • Seed. A seed version also comes out before the official release but, unlike a beta, is available only to participants in Apple’s testing and feedback program, AppleSeed. Taking part in the program is voluntary and by invitation only. As a participant you are in effect taking part in shaping Apple’s software, so you are expected to give active feedback. In fact, failure to do so may get you excluded from the program. Similarly to betas, you cannot release an app built with a seed, unless it has been labeled Gold Master (GM).

  • Official release. An official release is made after Apple’s new or updated development tools have undergone rigorous testing and customer feedback as betas and as seeds, so you can expect it to be as stable and as polished as it gets. The release version is the one you are expected to build your apps with before you release them in Apple’s App Store. Note that to publish your apps in the store you will need to be a member of the Apple Developer Program, which requires paid membership.

We will go through the steps for obtaining an official Xcode release and a beta.

Option A: Get the Official Release

If you want to build apps for the app store, you will need the latest official version of Xcode and the iOS SDK. Open the Store app on your Mac and do a search for Xcode. Then click Install (Figure 1-1 ). This will take care of the download and the installation in one go.

A371202_1_En_1_Fig1_HTML.jpg
Figure 1-1. Option 1: Download Xcode from Apple’s App Store

Option B: Get the Latest Beta

If the timeline for releasing your app is further in the future, you might prefer an even newer version of Xcode with the latest additions to Apple’s SDKs, You can go for an early beta, usually available from Apple’s web site at https://developer.apple.com/xcode/download/ (Figure 1-2). This will download a .dmg file, which you can double-click to start the installation.

A371202_1_En_1_Fig2_HTML.jpg
Figure 1-2. Option 2: Download an Xcode beta from Apple’s web site

Step 2: Run Xcode

Now that you have downloaded and installed Xcode, let us run it and see what it looks like out of the box. We will also lift the curtain a bit and have a look at where the SDK files are, as well as other locations that will come in handy when you start developing apps.

Running Xcode for the First Time

The very first thing you see when you run Xcode after its installation is a License Agreement, which starts with the preemptive “Please scroll down and read all of the following terms and conditions carefully. . .” (Figure 1-3).

A371202_1_En_1_Fig3_HTML.jpg
Figure 1-3. You need to agree with Xcode’s License Agreement before you can use it

After scrolling down, reading carefully for about a whole of five lines, then clicking Agree anyway, Xcode’s welcome screen appears (Figure 1-4). If you are anxious to begin development, jump straight to Chapter 2 , which shows you how to make and run your first iOS application.

A371202_1_En_1_Fig4_HTML.jpg
Figure 1-4. Xcode’s welcome screen

Where Does It All Go?

If you like to be in control of your machine and development environment, take a detour with me and let us see where Xcode installs things. This is useful for when you want to do more advanced maintenance of your tools: check what’s in the SDK, find logs when Xcode crashes (yes, it does . . .); know where it places your projects’ temporary files among other things.

The Xcode Installation Folder

To find where Xcode was installed, open Terminal on your Mac and run the following command:

xcode-select --print-path.

This will give you the path to Xcode’s installation folder, typically /Applications/Xcode.app/Contents/Developer/. To explore it in Finder, navigate to Xcode.app, right-click on it, select Show Package Contents and open the Contents folder.

The iOS SDK

You can find the iOS SDK that comes with Xcode in the Developer/Platforms/iPhoneOS.platform/Developer/SDKs folder inside the Xcode installation.

Location Settings

Xcode gives you control over where certain things should be found or stored. From Xcode’s main menu select XcodePreferencesLocations to see what you can set (Figure 1-5).

A371202_1_En_1_Fig5_HTML.jpg
Figure 1-5. Open Xcode ➤ Preferences ➤ Locations to see paths to important folders for your projects

Following is a brief description of each of the locations you can control:

  • Derived Data. Xcode uses two folders for putting temporary files when building a project: one is the build folder, which is always located in your project’s directory; the other one is called Derived Data and you have a choice of where this goes: in the same location as the project or in the folder shared by all of your projects. It is good to know the location of this folder for dealing with compilation problems where a simple project clean doesn’t seem to do the job. Deleting a project’s Derived Data and build folders is equivalent to doing a manual clean.

  • Archives. This is the location of the .xcarchive files Xcode creates for your projects: these contain your app executable and a .DSYM file—a file with debug information, which allows you to symbolicate a crash log, for example. You may have also used this to debug iOS native extensions for AIR.

  • Command-Line Tools. Here you can choose the path to Xcode’s command-line tools, in case you have more than one Xcode installation, thus more than one toolchain.

Documentation Settings

One thing you will not find in your fresh Xcode installation is documentation, as Apple provides comprehensive guides and manuals online. Sometimes, however, it is useful to be able to look things up when you are not connected to the Internet (long plane rides and family holidays in remote locations come to mind). To make any part of the documentation available offline open XcodePreferencesComponentsDocumentation and click the arrow next to a document to download it (Figure 1-6). Documentation is stored in ∼/Library/Developer/Shared/Documentation/DocSets.

A371202_1_En_1_Fig6_HTML.jpg
Figure 1-6. Make documentation available for offline reading from Xcode ➤ Preferences ➤ Components

Use the same pane to keep your offline documentation up to date: click the Check and Install Now button to get an update if one is available.

Step 3: Tell Xcode Who You Are

“Are we nearly there yet?” I can almost hear you say . . . I can’t blame you: I am a coder at heart and to say that I don’t enjoy following lengthy setup procedures would be putting it mildly. If you want to run applications on a physical device, there is one more thing left to do: Xcode needs to know about you. This section explains why and shows you how to finish the setup.

If, on the other hand, you would like to jump straight to creating your first native iOS app and see it run in a simulator, you can go to Chapter 2 and come back to this step when you need to.

Before you can install and test your apps on physical devices the apps will need to be cryptographically signed. A code signature uses a signing identity to ascertain that an app was developed and built by you and a certificate, created specifically for that app or for a group of apps, which allows the group members to use particular services. A signing identity is based on your Apple ID: Xcode can create one for you and install it in Keychain Access automatically.

To help Xcode create a signing identity , you need to let it know your Apple ID: from Xcode’s main menu select XcodePreferences and in the dialog that appears open the Accounts tab (Figure 1-6). Click the + button to add a new account and enter your Apple ID and password.

After your account has been added and appears in the Apple ID column, select it, then select the relevant Team in the right part of the dialog shown in Figure 1-7—this could be a development team your Apple ID is part of or just your Apple ID. Then click the View Details… button. This will open another dialog with a list of signing identities (Figure 1-8).

A371202_1_En_1_Fig7_HTML.jpg
Figure 1-7. Let Xcode know who you are by adding your Apple ID in Xcode ➤ Preferences ➤ Accounts
A371202_1_En_1_Fig8_HTML.jpg
Figure 1-8. Xcode 7 can create a signing identity for you

A signing identity is effectively a certificate that will be installed in the keychain of your development machine and is used to sign the apps you build. For the purposes of the tutorials in this book we will need an iOS Development signing identity. Select it from the list and click the Create button.

To see what Xcode has created, launch the Keychain Access app on your Mac. Under Keychainsselect login and under Category select My Certificates. Your signing identity should appear in the list on the right as iPhone Developer: <The name you registered your Apple ID with> and should say certificate in the Kind column (Figure 1-9).

A371202_1_En_1_Fig9_HTML.jpg
Figure 1-9. Check what Xcode has created in Keychain Access ➤ login ➤ My Certificates

Summary

Remember the workbench image, with which we opened this chapter? I hope that this is how your development machine looks and feels now: the tools for native iOS development laid out and ready to start crafting beautiful code. I’m afraid you will have to make the cup of coffee yourself, though.

With your choice of motivational drink ready, let us get on with making your first application in Chapter 2 .

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset