Both of your view controllers have quite a few methods in their implementation files. To be effective iOS developers, you must be able to go to the code you are looking for quickly and easily. The source editor jump bar in Xcode is one tool at your disposal to help out with this (Figure 11.14).
The jump bar shows you where exactly you are within the project (and also where the cursor is within a given file). Figure 11.15 breaks down the jump bar details.
The breadcrumb trail navigation of the jump bar mirrors the project navigation hierarchy. If you click on any of the sections, you will be presented with a popover of that section in the project hierarchy, and from there you can easily navigate to other parts of the project.
Figure 11.16 shows off the file popover in the Homepwner application.
Perhaps most useful is the ability to navigate easily within an implementation file. If you click on the last element in the breadcrumb trail, you will get a popover with the contents of the file including all of the methods implemented within that file.
While the popover is still visible, you can start typing to filter the items in the list. At any point, you can then use the up and down arrow keys and then press the Enter key to jump to that method in the code. Figure 11.17 shows what you get when you search for “indexpath” in BNRItemsViewController.m.
As your classes get longer, it can get more difficult to find the method you are looking for when it is buried in a long list of methods. A good way to organize your methods to help with the mess is by using the #pragma mark preprocessor directive.
#pragma mark - View life cycle - (void)viewDidLoad {...} - (void)viewWillAppear:(BOOL)animated {...} #pragma mark - Actions - (void)addNewItem:(id)sender {...}
Adding #pragma marks to your code does not change anything with the code, but instead helps Xcode understand how you would like to visually organize your methods. You can see the results of adding them by opening the current file item in the jump bar. Figure 11.18 shows the results of a well-organized BNRItemsViewController.m.
Two useful #pragma marks are the divider and the label.
// This is a divider #pragma mark - // This is a label #pragma mark My Awesome Methods // They can be combined as well #pragma mark - My Awesome Methods
By using the #pragma mark directive, you force yourself to organize your code. If done well, this will make your code more readable and easier for you to work with when you inevitably need to revisit the code. After doing it repeatedly, you will build habits which will further help you navigate your code base.