10 Xcode power user tips for iPhone devs

Xcode

If you're developing apps or games for Apple's iPhone/iPad/Touch devices, chances are you're using Xcode. Xcode has a lot of great features that can help increase productivity, so we thought we'd put together a list of ten power user tips for those new to the environment.

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:

  1. // Created by stephen on 10-05-18.
  2. // Copyright 2010 __MyCompanyName__. All rights reserved.

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

  1. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions "{ "ORGANIZATIONNAME" = "ReignDesign";}"

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:

  1. #pragma mark -
  2. #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:

  1. // MARK: Cleanup

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

  1. //TODO:
  2. //FIXME:
  3. //!!!:
  4. //???:

Have a great Xcode productivity tip that we missed? Let us know in the comments!

Stephen Ceresia

Stephen Ceresia is Marketing Manager at ReignDesign. Stephen is from Canada and is currently based in Shanghai.

6 comments

  1. thanks for these excellent tipps! I’ve been working quite some time with XCode but I missed some of the things you mentioned here! Thx!

  2. One of my favorite tips (most modern IDE’s have something like this) is using three forward slashes to auto-document your code. Whatever you put after those slashes will automatically pop up when you option-click on that method *anywhere* in your project, just like you get with the Cocoa API’s. It’s a fantastic tool, especially for collaborative projects!!

  3. You can also do:

    #pragma mark – My COol Section

    This will make a separator appear before it. This is the same as:

    #pragma mark –
    #pragma mark My COol Section

  4. Another power user tip:

    Command-Option-Shift click on almost anything and you’ll be presented with a wicked pop-up that lets you open a new tab, window, or panel that jumps to the place in code where the thing you clicked on is defined or, if it’s a file, the file.

    Command-control up arrow or down arrow to toggle between header and implementation files 😀

    Command-control right arrow and left arrow goes back and forth like clicking the navigation symbols at the top left of the main code window.

    Get a Razr Naga mouse and map all these to the numeric keypad on the side of the mouse and be a code-ninja…

Leave a Reply

Your email address will not be published. Required fields are marked *