18 Comments

Xcode Efficiency Tips: Keyboard Shortcuts

xcodegraniteincon

Although other IDEs exist, Apple’s Xcode remains the most popular choice for development of iOS applications. At Atomic, we highly value efficiency, so it’s important for a developer working in Xcode to familiarize themselves with at least some of the most useful keyboard shortcuts. To that end, this blog post will cover some of the keyboard shortcuts and resources I find myself using the most.

Exhaustive Shortcut Lists

Before mentioning specific shortcuts, here’s a link to the shortcut documentation from Apple: command shortcuts . Many developers have also created useful cheat sheets for quick reference.

Big lists are great for reference, but I find it is easier to learn a new IDE in small bits, starting with what seems to be the most useful bits first (the low hanging fruit).

Finally, here are the Mac modifier keyboard symbols and what they represent (these are frustratingly non-obvious for a newcomer to Mac- for instance, why don’t the control or alt/option keys on my macbook pro keyboard also have the symbols?):

⌘ = Command
⇧ = Shift
⌥ = Option/Alt
⌃ = Control
⇠⇢ = Left/Right Arrow Keys
⇡⇣ = Up/Down Arrow Keys

Getting around Xcode’s Workspace Windows

Xcode breaks up its main workspace window into several sub-areas. When describing keyboard shortcuts, it is informative to keep these areas in mind:

  • The Editor – where most coding work is done.
  • The Navigator – where a developer can navigate through tests, project files, compiler errors, breakpoints, etc.
  • The Debug Area – used during debugging.
  • The Utility Area – quick help, file and data descriptions, etc.

workspace

Because of all the sub-areas in the workspace, screen space can get used up very quickly. That makes it important to be able to hide areas you don’t need when you aren’t using them. The utility area is a good example: when working on a storyboard or nib, I use the utility are a lot. When coding, I only find myself looking at it for quick help, so I will often hide it. Similarly, the debug area doesn’t serve a purpose when not debugging or examining output. Apple has provided shortcuts for showing and hiding all of these areas, and I found a great blog post by Robert Saunders with a helpful map (I have highlighted the shortcuts for showing/hiding areas in red):

xcodeShortcuts

Navigating in the Editor

The single most useful feature for navigating code is ⇧ + ⌘ + O, which Apple calls “Open Quickly…”, but is actually an awesome, super-fast fuzzy search for file names. As you type, the file list is quickly populated, and you can use the arrow keys to select the file to open:

ShiftCmdO

“Open Quickly…” is essential on larger projects where searching through the project navigator is not an option (if you want to remain sane).

My other most-used hotkeys in the Editor are:

⌃ + ⌘ + ⇡ OR ⇣
⌘ + click on a variable/type
⌃ + ⌘ + ⇠ OR ⇢
⌃ + ⌘ + E
⌘ + T
⌘ + W
⇧ + ⌘ + [ OR ]
Switch between .m and .h files
Go to definition
Go forward / Go back
Edit all in scope
Open a new tab
Close the current tab
Go forward / Go back in tabs

Building, Running, Testing

Xcode puts a big “play” button in the upper left corner of the workspace and many build/clean/run options in the Product menu, but using keyboard shortcuts for these common tasks is a big time saver:

⌘ + B
⇧ + ⌘ + K
⌘ + R
⌘ + U
⇧ + ⌘ + ⌥ + G
Build
Clean
Run (build if necessary)
Run tests (build if necessary)
Re-run the last run tests

Debugging

Lastly, there are a few shortcuts I find myself using over and over again while debugging:

F6
F7
⌘ + \
⌘ + Y
⌃ + ⌘ + Y
Step over
Step into
Add/remove breakpoint
Disable/enable all breakpoints
Pause/Play the debugger

Learning and using Xcode keyboard shortcuts enough to build up muscle memory has really improved my coding speed and efficiency. Whenever I talk hotkeys with other iOS developers (exciting!) we always seem to teach each other new keyboard shortcuts — so I’d love to hear from other developers out there which they find most useful; I’m sure I’ve missed some!