Xcode Dev Tips

1. Quickly switch between .h and .m files

One of the more common tasks you’ll be doing is switching between interface and implementation files. As luck would have it, there are a couple of shortcuts to do this so you don’t have to manually select the files each time:

  • Click the Go to Counterpart double-squares icon in the top-right corner of the editing window.
  • Use the keyboard shortcut ⌘ Command + ⌥ Option + Up arrow.

2. Change default company name at the top of each .h and .m file

When you create class files in Xcode, you’ll notice the header contains default some boilerplate information commented out:

// Created by stephen on 10-05-18.

// Copyright 2010 __MyCompanyName__. All rights reserved.

To customize the company name, open up a terminal and enter the following:

defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions “{ “ORGANIZATIONNAME” = “DevCenter”;}”

replacing ReignDesign with your company name. Restart Xcode for the change to take effect.

3. Symbol identifier definitions

To jump to the definition for any symbol, hold ⌘ Command + double-click the symbol. For example, if you hold ⌘ Command + double-click a method name, you’ll be brought to its .h definition.

4. Symbol documentation

Symbol documentation

To bring up a brief documentation abstract for any symbol, hold ⌥ Option + double-click the symbol (the cursor will become a crosshair).

Information about the symbol will be displayed in a small window with links to its documentation page and definition.

5. Parenthesis matching

Parenthesis matching

Lost in a nest of if statements? Just double click any bracket or parenthesis, to see its corresponding open or closed counterpart.

6. Edit all in scope

Edit all in scope

Need to rename a variable but don’t want to do it manually, and don’t trust Find and Replace?

Right-click its name and choose Edit all in scope. All instances will be selected, and when you start typing they’ll be modified.

7. ESC to pop-up available code completion options

Available code completion options

Code completion is great, but sometimes it just doesn’t provide what you’re looking for. In these instances, if you press the Escape key, Xcode will pop-up a list of possible suggestions.

8. Snapshots

Snapshots

Xcode’s “Make Snapshot” option enables you to take a snapshot of your project’s current state and revert back to it. You can also save multiple snapshots. To take a Snapshot, click File and choose Make Snapshot.

Note: Xcode’s Snapshot feature hasn’t been 100% reliable for some users. While it is a useful and convenient feature, we’d suggest not relying on it as your only form of back up!

9. Re-indent selection

After rewriting that method a few times, your code may not be lined up as perfectly as you’d like. In these cases, Xcode can re-format the code for you so it lines up:

  • Select the area of text you wish to reformat
  • Right-click the selection and choose Re-Indent selection from the context menu

Voila! Your code is neatly lined up. Works well with Parenthesis matching.

10. Pragma mark directives, //TODO:, //FIXME:, //!!!:, and //???:

pragma marks

As your implementation files grow, pragma marks can be an extremely useful way to keep things organized. For example:

#pragma mark –

#pragma mark Cleanup

Note that there is no space after the dash in the first #pragma mark. An alternative – since #pragma mark directives are compiler dependent – is to use// MARK:. For example:

// MARK: Cleanup

In addition to using pragma marks, you can also use the following tags to make certain items stand out:

//TODO:

//FIXME:

//!!!:

//???: