Mishra Abhishek

Swift iOS 24-Hour Trainer


Скачать книгу

rel="nofollow" href="http://www.wrox.com/go/swiftios">www.wrox.com/go/swiftios.

      • iPhone App 2x: Use the file iPhoneAppIcon2x.png.

      • iPhone App 3x: Use the file iPhoneAppIcon3x.png.

      • iPad App 1x: Use the file iPadAppIcon1x.png.

      • iPad App 2x: Use the file iPadAppIcon2x.png.

After these assignments are made, your scene should resemble Figure 1.12.

Figure 1.12

      • Test your app in the iOS Simulator by clicking the Run button in the Xcode toolbar. Alternatively, you can use the Project arrow Run menu item.

      REFERENCE

      To see some of the examples from this lesson, watch the Lesson 1 video online at www.wrox.com/go/swiftiosvid.

Lesson 2

      A Tour of Xcode and the iOS Simulator

      Xcode is Apple's IDE (integrated development environment), which you use to create iOS applications. The word “integrated” refers to the fact that Xcode brings together several different tools into a single application.

      Xcode contains several tools, but the ones you'll use most of the time are the source code editor, debugger, and the Interface Builder. At the time of this writing, the current version of Xcode is 7.0.

      The iOS Simulator is an application that runs on your Mac and allows you to test your apps without using an actual iOS device. The iOS Simulator is part of the standard iOS SDK installation. When you run your app in Xcode, you have the choice of launching it in the simulator or an actual device. If you choose to launch it in the simulator, Xcode will launch the iOS Simulator automatically.

      In this lesson, you explore various commonly used features of Xcode and the iOS Simulator.

      The Welcome Screen

When you launch Xcode, you are presented with the welcome dialog box (Figure 2.1). You can use the welcome dialog box to quickly create a new project, connect to a source code repository, open a recently used project, or create a Swift playground.

Figure 2.1

      The first step in creating an iOS application is to create an appropriate project in Xcode. An Xcode project has the file extension .xcodeproj and tells the Xcode IDE (among other things) the name of your application, what kind of application it is (iPhone/iPad/Universal), and where to find the code files and resources required to create the application.

      Creating a New Project

When you create a new project in Xcode, you first need to select a template on which to base the project. Xcode templates contain files that you need to start developing a new application. Xcode provides a list of project templates to select from (Figure 2.2).

Figure 2.2

      The Xcode template window has multiple template categories to choose from. In this book, you create iOS applications, and thus need to make sure the iOS template category is selected.

After you have selected a suitable template, Xcode presents the project options dialog box (Figure 2.3).

Figure 2.3

      This is where you provide the name of the project and the name of your company, choose the language (Objective-C or Swift), and specify the target device (iPhone, iPad, or Universal).

      To uniquely identify your application in the iTunes store (and on an iOS device), each project must have a unique identifier. This identifier is known as a bundle identifier and is created by combining the name of the project along with a company identifier that you provide in the project options dialog box. It is best to provide your website domain name in reversed format as the company identifier because domain names are guaranteed to be globally unique.

      Checking the Use Core Data checkbox will add necessary boilerplate code to allow your application to persist objects into a database using Core Data. Core Data is covered in Lesson 26; for the moment you can leave this box unchecked.

      Checking the Include Unit Tests and Include UI Tests checkboxes will create a project that includes unit interface tests and user tests, topics that are covered in Lessons 33 and 34, respectively. For the moment you should leave these boxes unchecked.

      When you click Next, Xcode will ask you to provide a location on your Mac where you would like to save the new project. Toward the bottom of this dialog box, you have the option to create a new Git repository for version control. Version control is beyond the scope of this book, so just uncheck the Source Control option in the dialog box.

      An Overview of the Xcode IDE

The Xcode IDE features a single window, called the workspace window (Figure 2.4), where you get most of your work done.

Figure 2.4

      The Navigator Area

The left side of the workspace window is the navigator area (Figure 2.5).

Figure 2.5

The navigator area consists of eight tabs; each of these tabs (called navigators) shows different aspects of the same project. You can switch between navigators using the navigator selector bar at the top of the navigator area (Figure 2.6).

Figure 2.6

      The Project Navigator

The project navigator (Figure 2.7) shows the contents of your project. Individual files are organized within groups that are represented as folders in a tree structure. The top-level node of this tree structure represents the project itself. These groups are purely logical and provide a convenient way to organize the contents of your project. A group may not necessarily correspond to actual folders on your hard drive.

Screenshot of Xcode IDE Project Navigator with two groups, Hello World and Products.

Figure 2.7

      When a new project is created, Xcode will create two groups (folders) under the project node. Figure 2.7 shows what the project navigator would look like if you were to create a new project using the Single View Application template called HelloWorld without unit tests or user interface tests.

      As