Chapter 2. The Grand Tour

WHAT'S IN THIS CHAPTER?

  • Learning about the Project

  • Understanding Menus and Editors

  • Getting Help

Starting up Xcode is sort of like walking through the front gates of Disneyland, or onto the campus of a major university, or even a big shopping mall for the very first time. It's vast and you have no idea where to go first. If you just start walking, you'll quickly be lost and disoriented, so you do what every first-time visitor does; you get a map.

Neither Xcode, nor any of those other places, has been intentionally designed to be cryptic or confusing. In fact, they all go out of their way to be as friendly and accommodating as possible. However, the sheer size and complexity of what they offer cause them to be perplexing and frustrating at times. If you take a moment to get a feel for the scope and organization of Xcode, your initial forays will be much more enjoyable. Start by getting your bearings.

THE PROJECT

The central construct in Xcode, both physically and metaphorically, is the project. Everything you will accomplish in Xcode begins with a project. In fact, without an open project Xcode won't do much beyond letting you browse the documentation and set some preferences. The spirit of your project is stored in a project document on your file system. The project window, shown in Figure 2-1, is the manifestation of that document.

FIGURE 2-1

Figure 2-1. FIGURE 2-1

Because you can't explore much in Xcode without a project, take the time to create one now. You can throw it away later.

Launch the Xcode application and follow these steps:

  1. From the Xcode File menu, choose the New Project command (Shift+Command+N). If you've just launched Xcode, click the big Create New Xcode Project button in the Welcome to Xcode window.

  2. In the Application group, choose the Cocoa Application template (the options don't matter), as shown in Figure 2-2. Click the Choose button.

  3. Enter Grand Tour for the project name.

  4. Pick a location for the new project and click the Save button.

FIGURE 2-2

Figure 2-2. FIGURE 2-2

Xcode creates a project folder, containing a project document in addition to the source and resource files generated by the template.

Use this project to explore the various groups in the project window. You can also build, run, and even debug this project right now. Explore the properties of source items, groups, and other objects by Right/Control+clicking them.

The project window is your central workspace. Here you organize and navigate your project's resources, settings, and targets. From here you can initiate builds, launch the application, or start the debugger. Most of the menu commands apply to the currently active project window.

The left side of the project window is the Groups & Files pane. This is where everything that constitutes your project is represented and organized. Resources can be put into groups for better management. Click the expansion triangle to the left of a group's icon to explore its contents.

The right side of the project window is a multipurpose pane. It usually shows the details of the selection made in the Groups & Files pane, but it can also be used as an editor — or you may not even have a right side to your window. Xcode provides different window layouts to suit your work style. Chapter 3 explains these different styles and how to navigate your workspace.

Source Groups

Broadly, the Groups & Files pane contains two kinds of groups. At the top is the project group. This has the same icon and name as the project document. The project group organizes all of the source files and resources that make up your project, and is generically referred to as the source group. Sources are the files and folders used in your project. This could consist of program source files, headers, property lists, image files, dynamic libraries, frameworks, testing code, and even other projects. None of these constituent parts are stored in the project document itself. The files you will use to build your project exist elsewhere on your file system. The project group only contains references to those sources, not the sources themselves. Chapter 5 explains how to create, manage, and organize source references in the project group.

Double-clicking any source item opens it in an editor, assuming the item type is one that can be edited in Xcode.

Smart Groups

The remaining groups are referred to as smart groups. Unlike the project group, which you can organize however you like, the smart groups each represent some specific kind of information about your project. These groups are self-organizing and update automatically to reflect the state of your project.

One of the most important smart groups is the Targets group. This group shows the targets defined in the project. Each product your project produces, typically an executable program, is represented by a target. A target is organized into build phases. Each build phase performs a specific step in the build process, such as compiling all of the source files for a target or copying a set of files into the resource folder of an application bundle. A source is said to be a member of a target if the target includes that source item in any of its phases. Targets can depend on other targets, and they are highly customizable and extensible. Chapter 16 explains the kinds of targets Xcode provides and how to create your own. It also shows you how to organize and customize targets to meet your needs.

The Executables smart group lists the executables (programs that can be launched and run) in the project. Typically, each target produces one executable. The executables in a project can be run or debugged from within Xcode.

Most of the remaining smart groups gather information about your project, collecting them into readily accessible locations. For example, the Find Results smart group contains the history and results of recent searches. The Project Symbols smart group lists all of the symbols defined in your project. You can create your own smart groups that automatically collect source files that meet a certain criteria. If you've ever used smart playlists in iTunes, you are already familiar with this concept.

MENUS

The menus in Xcode are grouped by function. The File menu is where you'll find basic file and project commands. Use these commands to create new projects, files, and groups; close windows; save files; take snapshots; and print.

The Edit menu deals primarily with the editing of source files. The View menu controls the visual appearance of source files, windows, and lists. It also contains a number of file and window navigation commands. The Project menu contains commands specific to the project and its targets.

The Build, Run, Design, and SCM menus contain commands for building the project, debugging an executable program, class and data model design, and source control management, respectively. Each of these topics is covered in its own chapter. The Help menu is the gateway to the ADC reference library and the programming documentation. It also provides a few shortcuts to common topics.

The Window menu is one means of listing, and navigating between, the currently open windows. It also provides access to the organizer, described in Chapter 22.

EDITORS

Xcode includes a sophisticated and flexible set of editors. The one you'll use the most is the text file editor, shown in Figure 2-3. The text editor is context-sensitive, language-aware, and includes auto-completion features. It can automatically format, color, and highlight programming symbols and structures. The editor is integrated into the documentation, build system, and debugger. You can look up a symbol definition, jump to its declaration, review compiler errors, display the value of a variable, or step through your program without ever leaving the editor window. Its extensive editing and navigation features are covered in Chapter 6 and 7.

FIGURE 2-3

Figure 2-3. FIGURE 2-3

Xcode includes other kinds of editors, such as the property list editor, that enable you to edit the content of other document types easily. More sophisticated documents, most notably Interface Builder documents, are edited using separate applications that integrate with Xcode. You can also tap your favorite text, image, audio, or resource editor to augment, or replace, the editors provided by Xcode.

Chapter 13 discusses Interface Builder. Chapter 15 explains the data model editor.

SEARCHING, SYMBOLS, AND REFACTORING

Xcode includes many tools for exploring and altering the content and structure of your project. These are useful for finding something specific in your application and for understanding the structure of classes in an application.

The simplest of these tools are the various search commands. You can search a single file, or a group of files, for text patterns ranging from a sequence of characters to complex regular expressions. These commands are covered in Chapter 8.

The Class Browser, shown in Figure 2-4, compiles the classes and data structures in your application into a structured table. Chapter 9 shows you how to use it.

FIGURE 2-4

Figure 2-4. FIGURE 2-4

Chapter 14 introduces you to the class modeler. Like the Class Browser, it constructs a picture of your project's classes and their relationships. Unlike the Class Browser, the picture drawn by the class modeler is — well — a picture. The class modeler produces a graph of the classes in your application (see Figure 2-5). Models can be customized and are dynamically updated as you alter your code.

FIGURE 2-5

Figure 2-5. FIGURE 2-5

Chapter 10 describes the refactoring tool. This tool enables you to rename classes and variables intelligently, insert new classes into the hierarchy, relocate methods to a superclass or subclass, and upgrade legacy programming patterns to modern standards.

GETTING HELP

Someone once said, "It's not what you know, it's what you can find out." This sentiment is especially applicable to programming. It is impossible to remember every function name, every parameter, and every data type in the thousands of classes, headers, and libraries available to you. Often the question is not so much which specific function to call as it is "Where do I begin?"

Integrated into Xcode is the bulk of the Apple Developer Connection Reference Library, shown in Figure 2-6. This contains a vast wealth of introductory articles, examples, and programming guidance.

FIGURE 2-6

Figure 2-6. FIGURE 2-6

The Reference Library also includes a detailed, indexed, and searchable database documenting every major API in the Mac OS X and iPhone operating systems, an example of which is shown in Figure 2-7. You can instantly access the symbols in the Reference Library from within your source code or search the documentation interactively.

FIGURE 2-7

Figure 2-7. FIGURE 2-7

Being a productive programmer will largely depend on being able to quickly extract what you're looking for from this mountain of detail. Chapter 12 helps you find what you need.

BUILDING

The ultimate goal of any project is to produce something. Building takes the source items in your project and transforms them into a final product. Building can be roughly divided into two activities: defining how to build each product and then controlling what gets built and when.

The "how" portion is largely defined by the targets. Each target defines the steps and sources used to construct its product. This is explained in Chapter 16.

The "what and when" portion is explained in Chapter 17. This chapter explains how to initiate a build process and select exactly what you want to build. Most of the build process is witnessed through the project build window, shown in Figure 2-8.

FIGURE 2-8

Figure 2-8. FIGURE 2-8

Chapter 16 also explains Xcode's system of build settings and build configurations. Build settings are collections of options that control everything from what warnings the compiler will emit to the names of your executable files. A project contains multiple sets of build settings, forming a layered hierarchy of values. A build setting may apply to the entire project, or only to the files of certain targets, depending on where in the hierarchy the build setting is defined.

Build configurations add another dimension (literally) to build settings. Build configurations make it easy to configure projects that produce subtle variations of the same products, such as debug and release versions. You can also manage not-so-subtle variations; a single project target could produce an application for in-house testing, another version for use by the sales department, and a third variation for the field service engineers.

GETTING IT RIGHT

After your project is built, you then have to verify that it performs the way you intended it to. If any bugs are found, you must locate and correct them.

Xcode is integrated with several debuggers. Launching your application under the control of a debugger, as shown in Figure 2-9, enables you to step through the code in your application, view variables, and even fix bugs and alter data while it's running. The debugger facilities and commands are all explained in Chapter 18.

FIGURE 2-9

Figure 2-9. FIGURE 2-9

In addition to the debugger, you can employ unit testing and a cadre of performance and program analysis tools to help you identify, locate, and eliminate unwanted program behavior. Chapter 19 explains the analysis tools. Chapter 20 shows you how to set up your own unit tests.

COLLABORATION AND VERSION CONTROL

You can share projects and project sources with other projects and other developers. You can also configure your project to work directly with a variety of source control systems. Chapter 21 shows you how to create common pools of project resources and how to integrate your projects with a source control manager.

SUMMARY

This should give you some idea of the breadth and scope of the Xcode development environment. As you can see, there's a lot to cover in the subsequent chapters. You're probably anxious to get started, so move on to the next chapter to organize your workspace and learn your way around the interface.

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

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