Home > Articles > Operating Systems, Server > MAC OS X/Other

This chapter is from the book

Pragma Marks

Pragma marks organize your source code by adding bookmarks into the method list pop-up button at the top of each Xcode window. This list shows all the methods and functions available in the current document. Adding pragma marks lets you group related items together, as shown in Figure 3-22. By clicking these labels from the drop-down list, you can jump to a section of your file (for example, to Utility or RAOP) as well as to a specific method (such as -hexStringFromBytes:).

Figure 3-22

Figure 3-22. Use pragma marks to organize your method and function list.

To create a new bookmark, add a pragma mark definition to your code. To replicate the first group in Figure 3-22, for example, add the following:

#pragma mark Class

You can also add a separation line with a single dash. This uses a shortcut to add a spacer plus a mark:

#pragma mark –


#pragma mark – Marker Title

The marks have no functionality and otherwise do not affect your code. They are simply organizational tools you choose to use or not.

Collapsing Methods

When you need to see more than one part of your code at once, Xcode lets you close and open method groups. Place your mouse in the gutter directly to the left of any method. A pair of disclosure triangles appears. Click a triangle, and Xcode collapses the code for that method, as shown in Figure 3-23. The ellipsis indicates the collapsed method. Click the disclosure triangle, and Xcode reveals the collapsed code. You can also collapse any compound statement.

Figure 3-23

Figure 3-23. Xcode lets you collapse individual methods and functions. This allows you to see parts of your program that normally would not fit onscreen together.

  • + Share This
  • 🔖 Save To Your Account