Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Beginning iOS5 Development.pdf
Скачиваний:
7
Добавлен:
09.05.2015
Размер:
15.6 Mб
Скачать

CHAPTER 2: Appeasing the Tiki Gods

25

Figure 2–12. The Xcode navigator view showing the breakpoint navigator. The list of breakpoints is organized by file.

Log navigator: This navigator keeps a history of your recent build results and run logs (see Figure 2–13). Click a specific log, and the build command and any build issues are displayed in the edit pane.

Figure 2–13. The Xcode navigator view showing the log navigator. The log navigator displays a list of builds, with the details associated with a selected view displayed in the edit pane.

The Jump Bar

With a single click, the jump bar allows you to jump to a specific element in the hierarchy you are currently navigating. For example, Figure 2–14 shows a source file being edited in the edit pane. The jump bar is just above the source code. Here’s how it breaks down:

The funky looking icon at the left end of the jump bar is actually a popup menu that displays submenus listing recent files, unsaved files, counterparts, superclasses and subclasses, siblings, categories, includes, and files that include the current file.

www.it-ebooks.info

26CHAPTER 2: Appeasing the Tiki Gods

To the right of the über menu are left and right arrows that take you back to the previous file and return to the next file, respectively.

The jump bar includes a segmented popup that displays the files for the current project that can be displayed for the current editor. In Figure 2–14, we’re in the source code editor, so we see all the source files in our project. At the tail end of the jump bar is a popup that shows the methods and other symbols contained by the currently selected file. The jump bar in Figure 2–14 shows the file BIDAppDelegate.m, with a submenu listing the symbols defined in that file.

Figure 2–14. The Xcode editor pane showing the jump bar, with a source code file selected. The submenu shows the list of methods in the selected file.

The jump bar is incredibly powerful. Look for it as you make your way through the various interface elements that make up Xcode 4.

TIP: If you’re running Xcode under Lion (Mac OS X 10.7), there’s full support for full-screen mode. Just click the full-screen button in the upper right of the project window to try out

distraction-free, full-screen coding!

XCODE KEYBOARD SHORTCUTS

If you prefer navigating with keyboard shortcuts instead of mousing to on-screen controls, you’ll like what Xcode has to offer. Most actions that you will do regularly in Xcode have keyboard shortcuts assigned to them, such as B to build your application or N to create a new file.

You can change all of Xcode’s keyboard shortcuts, as well as assign shortcuts to commands that don’t already have one using Xcode’s preferences, under the Key Bindings tab.

A really handy keyboard shortcut is O, which is Xcode’s Open Quickly feature. After pressing it, start typing the name of a file, setting, or symbol, and Xcode will present you with a list of options. When you narrow down the list to the file you want, hitting return will open it in the editing pane, allowing you to switch files in just a few keystrokes.

www.it-ebooks.info

CHAPTER 2: Appeasing the Tiki Gods

27

The Utility Pane

As we mentioned earlier, the second-to-last button on the right side of the Xcode toolbar opens and closes the utility pane. Like an inspector, the utility pane is context-sensitive, with contents that change depending on what is being displayed in the editor pane.

You’ll see examples throughout the book.

Interface Builder

Earlier versions of Xcode included an interface design tool called Interface Builder, which allowed you to build and customize your project’s user interface. One of the major changes introduced in Xcode 4 is the integration of Interface Builder into the workspace itself. Interface Builder is no longer a separate stand-alone application, which means you don’t need to jump back and forth between Xcode and Interface Builder as your code and interface evolve. Huzzah!

We’ll be working extensively with Xcode’s interface-building functionality throughout the book, digging into all its nooks and crannies. In fact, we’ll do our first bit of interface building a bit later in this chapter.

New Compiler and Debugger

One of the most important changes brought in by Xcode 4 lies under the hood: a brandnew compiler and low-level debugger. Both are significantly faster and smarter than their predecessors.

The new compiler, LLVM 3, generates code that is faster by far than that generated by GCC, which was the default compiler in previous versions of Xcode. In addition to creating faster code, LLVM also knows more about your code, so it can generate smarter, more precise error messages and warnings.

LLVM can also offer more precise code completion, and it can make educated guesses as to the actual intent of a piece of code when it produces a warning, offering a popup menu of likely fixes. This makes errors like misspelled symbol names, mismatched parentheses, and missing semicolons a breeze to find and fix.

LLVM brings to the table a sophisticated static analyzer that can scan your code for a wide variety of potential problems, including problems with Objective-C memory management. In fact, LLVM is so smart about this that it can handle most memory management tasks for you, as long as you abide by a few simple rules when writing your code. We’ll look at the wonderful new ARC feature, which we mentioned earlier, starting in the next chapter.

www.it-ebooks.info

28

CHAPTER 2: Appeasing the Tiki Gods

A Closer Look at Our Project

Now that we’ve explored the Xcode workspace window, let’s take a look at the files that make up our new Hello World project. Switch to the project navigator by clicking the leftmost of the seven navigator icons on the left side of your workspace (as discussed in the “The Navigator View” section earlier in the chapter) or by pressing 1.

TIP: The seven navigator configurations can be accessed using the keyboard shortcuts 1 to

7. The numbers correspond to the icons starting on the left, so 1 is the project navigator,

2 is the symbol navigator, and so on up to 7, which takes you to the log navigator.

The first item in the project navigator list bears the same name as your project—in this case, Hello World. This item represents your entire project, and it’s also where projectspecific configuration can be done. If you single-click it, you’ll be able to edit a number of project configuration settings in Xcode’s editor. You don’t need to worry about those project-specific settings now, however. At the moment, the defaults will work fine.

Flip back to Figure 2–7. Notice that the disclosure triangle to the left of Hello World is open, showing a number of subfolders (which are called groups in Xcode):

Hello World: The first folder, which is always named after your project, is where you will spend the bulk of your time. This is where most of the code that you write will generally go, as will the files that make up your application’s user interface. You are free to create subfolders under the Hello World folder to help organize your code, and you’re even allowed to use other groups if you prefer a different organizational approach. While we won’t touch most of the files in this folder until next chapter, there is one file we will explore when we make use of Interface Builder in the next section:

BIDViewController.xib contains the user interface elements specific to your project’s main view controller.

Supporting Files: This folder contains source code files and resources that aren’t Objective-C classes but that are necessary to your project. Typically, you won’t spend a lot of time in the Other Sources folder.

When you create a new iPhone application project, this folder contains four files:

Hello_World-Info.plist is a property list that contains information about the application. We’ll look briefly at this file in the “Some iPhone Polish—Finishing Touches” section later in this chapter.

www.it-ebooks.info

CHAPTER 2: Appeasing the Tiki Gods

29

InfoPlist.strings is a text file that contains human-readable strings that may be referenced in the info property list. Unlike the info property list itself, this file can be localized, allowing you to include multiple language translations in your application (a topic we’ll cover in Chapter 21).

main.m contains your application’s main() method. You normally won’t need to edit or change this file. In fact, if you don’t know what you’re doing, it’s really a good idea not to touch it.

Hello_World_Prefix.pch is a list of header files from external frameworks that are used by your project (the extension .pch stands for precompiled header). The headers referenced in this file are typically ones that aren’t part of your project and aren’t likely to change very often. Xcode will precompile these headers and then continue to use that precompiled version in future builds, which will reduce the amount of time it takes to compile your project whenever you select Build or Run. It will be a while before you need to worry about this file, because the most commonly used header files are already included for you.

Frameworks: This folder is a special kind of library that can contain code as well as resources, such as image and sound files. Any framework or library that you add to this folder will be linked into your application, and your code will be able to use any objects, functions, and resources contained in that framework or library. The most commonly needed frameworks and libraries are linked into your project by default, so most of the time, you will not need to add anything to this folder. If you do need less commonly used libraries and frameworks, it’s easy to add them to the Frameworks folder. We’ll show you how to add frameworks in Chapter 7.

Products: This folder contains the application that this project produces when it is built. If you expand Products, you’ll see an item called Hello World.app, which is the application that this particular project creates. Hello World.app is this project’s only product. Because we have never built it, Hello World.app is red, which is Xcode’s way of telling you that a file reference points to something that is not there.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]