How to Find and Search in Your iOS App with Xcode
You’ll find that, as your iOS app classes get bigger, sometimes you’ll want to find a symbol or some other text in your project. Xcode provides a number of ways to do that.
Using the Find command to locate an item in a file
Need to track down a single symbol or all occurrences of a symbol in a file or class? You can easily locate what you’re looking for by using the Find menu or pressing ⌘+F, which opens a Find toolbar above the Editor pane to help you search the file in the editor.
The Find menu has 15 find-and-replace submenus. The keyboard equivalent ⌘+F opens a find-and-replace bar above the Editor pane. They are not the same.
For example, if you enter viewDidLoad in the Find toolbar. Xcode found two instances of viewDidLoad in the source editor and highlighted them. (Admittedly, the first highlight is a tad darker.)
You can jump from one instance to the next by pressing ⌘+G. Or you can use the Previous and Next buttons (left and right arrows) on the Find bar.
Click the Find pop-up menu on Find toolbar and choose Replace to do a file-level replace.
Click the magnifying glass in the Search field in the Find toolbar to display a menu that allows you to show or hide the Find options. For example, you can choose to ignore or match the case of the text in the Search field. Changes you make to this set of options remain persistent for future searches.
Using the Search navigator to search your project or framework
Whereas the Find command works for locating an item in a file or class, you use the Find navigator (the third button from the left in the Navigator selector) to find items in your project or even frameworks. You can use Shift+Command+F as a handy keyboard shortcut for the Find command in the Workspace menu item, which also opens the Find navigator pane.
Notice that viewDidLoad was entered in the Find field. The magnifying glass in the Find field was also clicked to display search options. (Clicking in the Find pop-up menu will also let you choose Replace to perform a global replace.)
Note how the initial results of the search are displayed in the Find navigator; if you wanted to filter the Results list still further, you could enter text into the field at the bottom of the pane. Any items that don’t match the text are removed from the Results list.
To go directly to where the search term appears in a file, click an entry under the file’s name in the Find navigator. The file appears in the editor pane on the right, open to the location where the search term appears.
Using the Symbol navigator
The Symbol navigator allows you to browse through the symbols in your project — just click the Symbol button on the Navigator selector bar. Note that you need to wait until Xcode finishes indexing your project before you can use this feature.
You can display symbols in a hierarchical or flat list using the buttons at the top of the Symbol navigator.
You can specify which symbols are displayed by using the buttons at the bottom of the navigator. Buttons are blue when on and black when off. Use the following buttons in any combination:
Thefirst button on the Symbol navigator shows only class symbols and hides global symbol types.
Themiddle button shows only symbols in this project.
Thethird button shows only containers (classes and categories).
You can refine the Results list still more by entering text in the Filter field at the bottom of the navigator.
If you select a symbol to display, its header file definition will be displayed in the source editor. Below, everything was hidden but the member symbols. In the resulting list, the viewDidLoad method was filtered, and its declaration in the header file was highlighted in the source editor.