iPhone Developer Tips Stats:
|
Killer Xcode Tips and Tricks – Tips 1 to 10
My world is surrounded by sticky notes, both electronic and paper, doing my best to keep track of Xcode shortcuts, tips and tricks. I strive to use the mouse as little as possible when coding, and without these tips I’d be lost. What better place to keep track of this stuff than to write about them here.
This is the first post of what I hope is many where we can share tips and tricks on working with Xcode.
Tip #1 – Split Editor View Vertically
If you like to have multiple code windows open at once, the Split Editor option is your friend (see the little square grid icon shown below).

By default, the windows are split horizontally. If you prefer to view your code side-by-side (nice for comparing), here’s how to tell the split to be vertical
- Hold down Option key when clicking the Split Window icon
Tip #2 – Comment Out a Block of Code
You can quickly comment out a block of code as follows:
- Select one or more lines of code to comment
- Command-/
To uncomment a block of code, repeat the steps above.
Tip #3 – Toggle Between .h and .m Files (aka Switch to Counterpart)
Within your current code window, you can swap between the .h and .m file as follows:
- Command-Option Up-Arrow
Tip #4 – Map Keys to Actions (Key Bindings)
The Switch to Counterpart tip above is a real time saver. However, I often find that if I map logical key-strokes to actions I’m much more likely to get into the habit of using them. For example, I mapped the Switch to Counterpart to Option-S, as in Swap or Switch.
Here’s how to set key bindings in Xcode
- From the Xcode menu choose Prefereces
- Select Key Bindings
- Click on one of the Actions in the list
- Tap on the Keys column on the right
- Enter the keystroke you want to map to the action
- Click Ok to save your changes
Tip #5 – Jump to API Documentation
Showing relevant API documentation for anything within the SDK(s) is as simple as:
- Option Double-Click on relevant code
For example, in the screenshot below, after Option double-clicking on UIToolbar, a popup window shows a summary of the class information.

Tip #6 – Traverse File History
As you open and edit various files, Xcode keeps a history list of your actions, not unlike when using a web-browser. You can move through the list using the directional arrows as shown below:

The keystoke equivalent for the above is:
- Option-Command Left-Arrow goto to previous file
- Option-Command Right-Arrow goto to next file
Tip #7 – Set a Bookmark
I can’t imagine coding without having the option to set a bookmark as a placeholder for what I’m working on. I do this regularly when I need to segue to another file to find a snippet or otherwise poke around outside the current file I’m working on.
Setting a bookmark is as simple as:
- Control-D
- Enter a name for the bookmark
Tip #8 – Jump to Bookmark
There are two options to jump to a bookmark. First, you can select the bookmark icon in the upper right corner of the Editor window.

You can bring up the same menu as shown in the above figure using this keystoke:
- Control-4
Tip #9 – Indent / Un-indent Code
You can indent a line of code or a selected block of code as follows:
- Command-[ move code left
- Command-] move code right
The above works regardless of where you are in a line of code, in other words, you don’t have to be at the beginning of the line.
Tip #10 – Zoom Editor
You can toggle between Detail view and Editor view by clicking the Editor button as shown here:

The keystroke equivalent of the above is:
- Shift-Command-E
Have an Xcode Tip to Share?
If you have a favorite tip or trick, please post a comment or send tips to me here. Killer Xcode Tips and Tricks – Tips 11 to 20 will be posted next week, and suggestions are welcome!









Open files quickly: cmd + option + D
#3 alternative – from a laptop – three finger swipe up will take you from .h -> .m -> .h etc.
three finger swipe down will take you from the declaration/implementation of the method the cursor is currently in.
#6 alternative – Three finger swipe left and three finger swipe right will move you backwards/forwards through your editor history.
Whow!!!!! Thank you! 8 out of 10 i did not know!
Absolutely awesome post!
1. Indent selection: Ctrl+I
I use this constantly to re-indent code I’m editing. I never use the manual-indent keystrokes anymore.
2. Pop Symbols PopUp: Command+Option+2
By default this may have a different shortcut, maybe Ctrl+2. Pop-up the symbols then begin typing the method name you’re looking for. It’s a quick way to find a method in the current file.
3. Go to declaration/definition: Command+Double Click.
For example, double-clicking “NSString” takes you the NSString header.
4. Close All: Command+Option+W
This closes all windows of a similar type. Useful in the “Condensed” and “Default” layouts. For example, Option+Close on a source code window closes all source code windows. Option+Close on a debugger window closes all debugger windows.
5. Switch to Symbolic Counterpart: Command+Option+Shift+Up
This doesn’t have a keyboard shortcut by default, but it can be very handy.
When the cursor is in a method or function definition, this takes you to that method’s declaration, and vice versa, even if the declaration and definition are in the same file. E.g., for private interfaces declared in a .m file.
6. Compile: Command+K
Maybe obvious, but worth mentioning. This compiles only the current source file. It’s a quick way to check for syntax errors without doing a full build.
7. Next/Prev Build Warning: Command+=, Command+Shift+=
After a build, use this to iterate over any warnings and errors.
8. Strip Trailing Spaces (Scripts!)
I bet most people don’t realize how easy it is to create custom scripts in XCode.
Try this:
- Script Menu > Edit User Scripts…
- New Shell Script
- Input: Entire Document
- Output: Replace Document Contents
- Script:
#!/usr/bin/perl
while () {
s/\s+$//;
print “$_\n”;
}
Give it a name and a keyboard shortcut, and now you have keyboard shortcut for stripping trailing spaces from a document.
Vim fans should take a look at cocoa.vim and the Vi Input Manager!