Chapter    1

Setting Up the Development Environment

It is more fun to see apps run than to read the source code, and you cannot get hands-on programming experience by just reading books. Let’s get the development environment up and running first so you can use it—and learn Swift programming for iOS along the way.

There is no single integrated development environment (IDE) that can be called the IDE for web development. Eclipse and Eclipse-based products such as Aptana and Spket, and others such as NetBeans, IntelliJ Idea, and Visual Studio, are all popular tools for building and deploying web applications. In fact, some outstanding web developers use only a text editor to create Hypertext Markup Language (HTML), Cascading Style Sheets (CSS), or JavaScript files! In the iOS programming world, Apple purposely requires a single development environment for creating iOS apps. It makes for no jailbreakers, and all you need is the one tool: Xcode.

 Note  Rather than attempt to provide specific examples from every web IDE, this book will instead reference analogous tasks from web development where applicable.

Xcode and the iOS SDK

Xcode is a complete tool set for building iOS apps. In other words, it is an IDE that helps you build, test, debug, and package your iOS apps. It is free, but you must have an Intel-based Mac running Mac OS X Mavericks or newer. You will use the latest Xcode, version 6, throughout this book.

Installing from the Mac App Store

Xcode is distributed via the Mac App Store, which takes care of the download and install for you. With a single click to start the download and installation of Xcode, you get the compilers, code editor, iOS software development kit (SDK), debugger, device emulators, and everything you need to create iOS apps. Figure 1-1 shows Xcode in the Mac App Store.

9781484209325_Fig01-01.jpg

Figure 1-1. Xcode in Mac App Store

All you need to do is install the latest Xcode from the App Store. After completing the installation, launch Xcode from the Applications folder. Keep it in the Mac OS Dock so that you can launch it at any time.

The first time you launch Xcode, it immediately prompts you to install the required components (see Figure 1-2). Click Install to complete the Xcode installation.

9781484209325_Fig01-02.jpg

Figure 1-2. Install the required components

After the required components are installed, you should see the screen in Figure 1-3. Your iOS IDE, Xcode, is ready!

9781484209325_Fig01-03.jpg

Figure 1-3. Welcome to Xcode screen

Creating an iOS Project Using the Template

WEB ANALOGY

You can create a New Web Application project in Visual Studio, create a new project in Sencha Architect (and select a framework), use the web app project templates in Eclipse web projects, and so on.

You’ve got the right tool; now, wouldn’t you like to see some real action—like creating an iOS app and seeing it run? I’d like that, too! You want to do this to ensure your IDE is working properly as well.

Out of the box, Xcode offers the project creation templates that immediately give you a starting point that contains the minimal software artifacts for the given project types. The objective of this section is to show you how to create an iOS app as quickly as possible. Hold any programming questions so you can finish the project as fast as you can. For now, complete the following steps:

  1. Launch Xcode if you haven’t launched it yet.
  2. Click “Create a new Xcode project” on the Welcome to Xcode screen (shown earlier in Figure 1-3). Figure 1-4 shows the prompt that asks you to choose a template for your project.
    1. In the left panel of Figure 1-4, select iOS image Application.
    2. In the right panel of Figure 1-4, you may choose any of the templates. Just for fun, choose Game.

    9781484209325_Fig01-04.jpg

    Figure 1-4. Choose a template

  3. Click the Next button.
  4. Figure 1-5 depicts the basic project information that requires you to fill in the following:
    1. Product Name: This is the app name. Name your project LessonOne.
    2. Organization Name: This is optional; for example, you can use your organization’s name or any name you choose.
    3. Organization Identifier: Together with the product name, the organization identifier should uniquely identify your app. A reverse domain name is recommended (for example, com.yourdomain.xxx).
    4. Language, Game Technology, and Devices: You don’t need to change these settings.

    9781484209325_Fig01-05.jpg

    Figure 1-5. iOS project options

  5. Click the Next button when done.
  6. Select a folder in which to save your LessonOne project.

That is it! You just created an iOS project, the LessonOne project, that you can see the in Xcode as shown in Figure 1-6.

9781484209325_Fig01-06.jpg

Figure 1-6. LessonOne project in Xcode Project Navigator (left panel)

The LessonOne project can be seen on the left panel, as shown in Figure 1-6; this is the Project Navigator in the navigation area. The Xcode project template creates the project folder, the application source code, and all the resources for building the LessonOne apps.

Building the Project

WEB ANALOGY

This is the process that bundles, minifies, and packages your app and all the referenced code that will be deployed with it.

To build and compile the Xcode project, use the Build action, which is located in the Product image Build menu in Xcode (or press flower.jpg+B). You will get used to using the flower.jpg+B keyboard shortcut a lot because Xcode doesn’t automatically build your code (unlike Eclipse ADT, which builds it automatically by default).

Launching the App

The LessonOne project should have no errors. You can launch the app and see it run on an iOS emulator. The emulator is an important piece of any IDE, probably even more important for mobile apps. All the iOS devices emulators are right there in Xcode, and you can launch the LessonOne project on the selected device, including the iOS emulator, by clicking the triangle button in the upper-left corner, as shown earlier in Figure 1-6.

Alternatively, you can use the flower.jpg+R Xcode keyboard shortcut key for the Run action to launch the app. You should see your LessonOne app running on the iPhone emulator, as shown in Figure 1-7.

9781484209325_Fig01-07.jpg

Figure 1-7. LessonOne app in the emulator

Play with the app and then select other emulators from the device drop-down selector (see the pointer in Figure 1-6). A mouse-click event on an emulator is equivalent to a touch event, and three-finger movement on the trackpad is equivalent to a touch-drag on a physical iOS screen. If you don’t have a particular device yet, definitely play with the emulator to get familiar with the emulated iOS devices.

 Tip  To change to landscape or portrait orientation, press flower.jpg+left arrow or flower.jpg+right arrow to rotate the emulator.

The iOS emulators are robust and responsive, and they behave almost exactly like real devices. For learning Swift programming for iOS, the emulator actually is better. In this book, you are not required to run apps on a physical iOS device; for that you would need to be a registered iOS developer. You can save the $99 iOS developer membership fee until you are ready to submit your first app to the App Store or for when your app requires certain features not available in the emulator (for example, the camera or certain sensors). For your convenience, I have provided how to build and sign an app for on-device debugging in the appendix of this book. For now, if your app is launched and running on an iOS emulator, your mission is completed!

Summary

By installing Xcode 6, you immediately have a fully functional IDE ready to create iOS apps without hassle. This chapter walked you through the basic project creation tasks in Xcode 6, using an iOS project template to start your first iOS project. This chapter also showed you how to build and run your iOS app in iOS emulators. You haven’t written any code yet, but your Xcode tool is working and verified. You will learn more and gain hands-on programming experience from the guided exercises in the following chapters.

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

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