1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Wrox Professional Xcode 3 cho Mac OS part 2 ppt

10 258 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 2,65 MB

Nội dung

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 fi rst time. It ’ s vast and you have no idea where to go fi rst. If you just start walking, you ’ ll quickly be lost and disoriented, so you do what every fi rst - 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 fi le system. The project window, shown in Figure 2 - 1, is the manifestation of that document. ➤ ➤ ➤ c02.indd 9c02.indd 9 1/22/10 11:58:39 PM1/22/10 11:58:39 PM Download at getcoolebook.com 10 ❘ CHAPTER 2 THE GRAND TOUR 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-1 FIGURE 2-2 c02.indd 10c02.indd 10 1/22/10 11:58:45 PM1/22/10 11:58:45 PM Download at getcoolebook.com Xcode creates a project folder , containing a project document in addition to the source and resource fi les 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 fi les and resources that make up your project, and is generically referred to as the source group . Sources are the fi les and folders used in your project. This could consist of program source fi les, headers, property lists, image fi les, dynamic libraries, frameworks, testing code, and even other projects. None of these constituent parts are stored in the project document itself. The fi les you will use to build your project exist elsewhere on your fi le 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 specifi c kind of information about your project. These groups are self - organizing and update automatically to refl ect the state of your project. One of the most important smart groups is the Targets group. This group shows the targets defi ned 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 specifi c step in the build process, such as compiling all of the source fi les for a target or copying a set of fi les 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 The Project ❘ 11 c02.indd 11c02.indd 11 1/22/10 11:58:46 PM1/22/10 11:58:46 PM Download at getcoolebook.com 12 ❘ CHAPTER 2 THE GRAND TOUR 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 defi ned in your project. You can create your own smart groups that automatically collect source fi les 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 fi nd basic fi le and project commands. Use these commands to create new projects, fi les, and groups; close windows; save fi les; take snapshots; and print. The Edit menu deals primarily with the editing of source fi les. The View menu controls the visual appearance of source fi les, windows, and lists. It also contains a number of fi le and window navigation commands. The Project menu contains commands specifi c 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 fl exible set of editors. The one you ’ ll use the most is the text fi le 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 defi nition, 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 Chapters 6 and 7. c02.indd 12c02.indd 12 1/22/10 11:58:46 PM1/22/10 11:58:46 PM Download at getcoolebook.com 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 fi nding something specifi c 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 fi le, or a group of fi les, 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-3 Searching, Symbols, and Refactoring ❘ 13 c02.indd 13c02.indd 13 1/22/10 11:58:47 PM1/22/10 11:58:47 PM Download at getcoolebook.com 14 ❘ CHAPTER 2 THE GRAND TOUR 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-4 FIGURE 2-5 c02.indd 14c02.indd 14 1/22/10 11:58:48 PM1/22/10 11:58:48 PM Download at getcoolebook.com 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 fi nd 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 specifi c 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 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. Getting Help ❘ 15 c02.indd 15c02.indd 15 1/22/10 11:58:48 PM1/22/10 11:58:48 PM Download at getcoolebook.com 16 ❘ CHAPTER 2 THE GRAND TOUR 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 fi nd 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 fi nal product. Building can be roughly divided into two activities: defi ning how to build each product and then controlling what gets built and when. The “ how ” portion is largely defi ned by the targets. Each target defi nes 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-7 c02.indd 16c02.indd 16 1/22/10 11:58:49 PM1/22/10 11:58:49 PM Download at getcoolebook.com Chapter 16 also explains Xcode ’ s system of build settings and build confi gurations . Build settings are collections of options that control everything from what warnings the compiler will emit to the names of your executable fi les. 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 fi les of certain targets, depending on where in the hierarchy the build setting is defi ned. Build confi gurations add another dimension (literally) to build settings. Build confi gurations make it easy to confi gure 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 fi eld 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 fi x bugs and alter data while it ’ s running. The debugger facilities and commands are all explained in Chapter 18. FIGURE 2-8 Getting It Right ❘ 17 c02.indd 17c02.indd 17 1/22/10 11:58:50 PM1/22/10 11:58:50 PM Download at getcoolebook.com 18 ❘ CHAPTER 2 THE GRAND TOUR 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 confi gure 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. FIGURE 2-9 c02.indd 18c02.indd 18 1/22/10 11:58:51 PM1/22/10 11:58:51 PM Download at getcoolebook.com . 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- 1 FIGURE 2- 2 c 02. indd 10c 02. indd 10 1 /22 /10. window, shown in Figure 2 - 1, is the manifestation of that document. ➤ ➤ ➤ c 02. indd 9c 02. indd 9 1 /22 /10 11:58 :39 PM1 /22 /10 11:58 :39 PM Download at getcoolebook.com 10 ❘ CHAPTER 2 THE GRAND TOUR. navigation features are covered in Chapters 6 and 7. c 02. indd 12c 02. indd 12 1 /22 /10 11:58:46 PM1 /22 /10 11:58:46 PM Download at getcoolebook.com Xcode includes other kinds of editors, such as the

Ngày đăng: 04/07/2014, 06:20

TỪ KHÓA LIÊN QUAN