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
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:
- 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:
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:
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!