Mishra Abhishek

Swift iOS 24-Hour Trainer


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

you select a source-code file in the navigator area, or a text/XML file, Xcode uses the source editor to open the file. This is the editor with which you will spend most of your time when you write your code. The source editor has several helpful features, such as syntax highlighting and code completion hints. You can configure individual features of the source editor using Xcode preferences.

      The Assistant Editor

The assistant editor (Figure 2.16) was introduced in Xcode 4 and enables you to view multiple files side-by-side.

Screenshot of Xcode IDE Version Editor, with Assistant Editor labeled on the last right section.

Figure 2.16

      The assistant editor is not visible by default and can be accessed by using the editor selector buttons in the Xcode toolbar or by selecting View arrow Assistant Editor arrow Show Assistant Editor. Option-clicking a file in the project navigator or symbol navigator opens it in the assistant editor. You can create additional assistant editor panes by using the + button in the jump bar of the assistant editor.

      The Version Editor

      If your project is under version control, you can use the version editor to compare the current version of a file with a previous version. Like the assistant editor, the version editor is not visible by default and can be accessed by using the editor selector buttons in the Xcode toolbar. Version control is not covered in this book.

      The Utilities Area

The utilities area (Figure 2.17) supplements the editor area. You can display it by selecting View arrow Utilities arrow Show Utilities or by clicking the utility button in the toolbar.

Screenshot of Xcode IDE Utilities Area, with Utilities Area labeled on the right section.

Figure 2.17

      The Inspector Area

The top portion of the utilities area contains the inspector area (Figure 2.18). Like the navigator area, the inspector area also contains multiple tabs that can be switched using a selector bar at the top of the window.

Screenshot of Xcode IDE Inspector Area.

Figure 2.18

      The number of tabs available depends on the currently selected item in the project navigator. Regardless of what is selected in the project navigator, the first two tabs are always the file inspector and the quick help inspector. The file inspector provides access to the properties of the current file. The quick help inspector provides a short description of the current file.

      The Library Area

The bottom portion of the utilities area contains the library area (Figure 2.19). This area contains a library of file templates, user interface objects, and code snippets that you can use in your applications.

Screenshot of Xcode IDE Library Area with options Cocoa Touch Class, UI Test Case Class, Unit Test Case Class, and Playground.

Figure 2.19

      The library area also provides a convenient method to access all the media files in your project. A selector bar at the top of the library area provides access to four different library categories.

      The Debugger Area

The debugger area (Figure 2.20) also supplements the editor area. You can access it by selecting View arrow Show Debug Area or by clicking the debugger button in the toolbar.

Screenshot of Xcode IDE Debugger Area, with Debugger Area labeled on the bottom center section.

Figure 2.20

      The debugger area is used while debugging an application and to access the debug console window. You can use this area to examine the values of variables in your programs.

      The Toolbar

The Xcode toolbar (Figure 2.21) is located at the top of the workspace window. Use the first two buttons on the left side to run/stop the active build scheme. Immediately following the stop button is the Scheme/Target multi-selector. When you create an iOS project, Xcode creates a scheme with the same name as the project and several build targets.

Screenshot of Xcode IDE Toolbar.

Figure 2.21

      The build targets that are typically generated for a project include:

      • iOS Device

      • iPad 2 (if it is an iPad or Universal project)

      • iPad Air (if it is an iPad or Universal project)

      • iPad Retina (if it is an iPad or Universal project)

      • iPhone 4S (if it is an iPhone or Universal project)

      • iPhone 5 (if it is an iPhone or Universal project)

      • iPhone 5S (if it is an iPhone or Universal project)

      • iPhone 6 Plus (if it is an iPhone or Universal project)

      • iPhone 6 (if it is an iPhone or Universal project)

      You can use the Scheme/Target multi-selector to switch build targets and create/edit schemes. Managing schemes is an advanced topic beyond the scope of this book.

      To the right of the Scheme/Target multi-selector is a status window. Following the status window, the toolbar contains the editor selector and utility selector buttons, which have been covered in the previous sections.

      Features of the iOS Simulator

When you run an application from the Xcode IDE, unless you have selected a device in the Scheme/Target multi-selector, your application will be launched in the iOS Simulator. Figure 2.22 shows the iPhone 5S simulator. You can use the iOS Simulator to simulate different device and SDK versions. To switch devices use the Hardware arrow Device menu.

Screenshot of iOS home screen, with Game Center, Extras (grayed), HelloSwift, and Watch icons at the top and Safari icon below.

Figure 2.22

      You can rotate the simulator by using the Rotate Left or Rotate Right menu items from the Hardware menu. The iOS Simulator allows you to simulate a variety of one and two-finger multi-touch gestures. Single-finger gestures such as taps and swipes can be performed by clicking and dragging with the mouse. The only two-finger gesture that you can simulate is the pinch. To do so, hold down the Option key on your keyboard while clicking and dragging with the mouse in the simulator window. Shake gestures can be performed by using the Hardware arrow Shake Gesture menu item.

If you are developing an app that requires location data, you can use the iOS Simulator to simulate a test location while you are running your application within the simulator. Select Debug arrow Location arrow Custom Location to specify a latitude and longitude pair (Figure 2.23).