Home > Articles > Home & Office Computing > Mac OS X

  • Print
  • + Share This
This chapter is from the book

Using Editors

The center of the workspace window is reserved for editing your project and its files. As you have seen, different editors are automatically opened for the different types of files in your project.

  • This section focuses on text editors; other editors are discussed in Hour 6, “Working with the Core Data Model Editor,” p. 117, and Hour 11, “Finding Your Way Around Interface Builder: The Graphics Story,” p. 189.

Using Editing Modes

Three editing modes are available in Xcode:

  • Standard—This displays a single file in the edit area.
  • Assistant—This displays two or more related files in the edit area.
  • Version—If you are using source control, you can compare a file with its previous version or versions.
  • Refer to “Working with Assistant” on p. 29 of this hour for details about the Assistant mode.

You select the editing mode with the trio of buttons marked Editor at the right of the top of the Xcode window, as shown in Figure 1.19. You can also use View, Editor to choose among them.

Figure 1.19

Figure 1.19 Select the assistant you want to use.

Using the Jump Bar

The jump bar appears at the top of the editor area no matter what mode you are in. As you can see in Figure 1.20, the jump bar above the editor area shows the path to the file you are working on relative to the project and lets you quickly navigate to a file, method, property, or class in the file. If you have several files open (as is often the case in Assistant and Version editor panes), each has its own jump bar.

Figure 1.20

Figure 1.20 Jump bar in action.

You can use it to quickly navigate to a file or to a method, property, or class in the open file.

Thus, at the left, you see the icon for the project (Master Detail Sample); within that, you see a group (Master Detail Sample—shown with a Finder folder icon), and within that, the filename is shown (Hour1_AppDelegate.m). The next level down is a list of the methods, properties, and classes in that file.

Organizing Your File’s Pop-Up Menu List

In addition to the names of the methods, properties, and classes, titles appear in the pop-up list. You put titles into the file using a pragma directive:

#pragma mark - headingName

There actually are three variations on this directive:

  • The example shown provides a bold-faced heading with a dividing line above it, as shown in Figure 1.20.
  • If you omit the hyphen, the dividing line is not shown and you only have the name.
  • If you omit the name but use the hyphen, you have an unnamed dividing line.

You can use the bold-faced heading with a dividing line for major sections of your code; then use dividing lines without headings to further divide each major section.

Using headers forces you to keep your file organized because related methods, properties, and classes are physically co-located in the file.

Using Xcode’s Organization Tools

Xcode keeps track of the relationships among your files. At the left of the jump bar, the related items menu lets you quickly jump to related files. You can see the related items menu in Figure 1.21.

Figure 1.21

Figure 1.21 Use the related items menu.

At the top of the menu, submenus show you unsaved files and recent files. Submenus show you these types of related files when you are looking at source code. Other types of files, such as nib files and Core Data model editor files, have different submenus:

  • Counterparts—This means the .h files for .m files, and vice versa.
  • Superclasses—There is always a superclass (except for NSObject). This list is organized in order so that the last item at the bottom is always NSObject.
  • Subclasses—If any.
  • Siblings—These are classes that share the same immediate superclass.
  • Categories—This is an Objective-C construct that allows you to add methods to an existing class.
  • Protocols—This Objective-C features lets you declare a set of methods that can be implemented by several classes in their own ways and with their own data structures. Protocols provide functionality similar to multiple inheritance in some other object-oriented languages.
    • Both categories and protocols are discussed in Hour 3, p. 63.
  • Includes—These are the files that are included in the file you are looking at.
  • Included By—From an included file, you can return easily to this file; you can also see the other files in your project that may include this file.

With these various navigational tools available and updated by Xcode, you might want to use the adjacent forward and back arrows. They function just as forward and back arrows do in a browser. This means that you can use the related items menu to explore the rest of your project and get back to where you started from with just a few mouse clicks.

  • + Share This
  • 🔖 Save To Your Account