Tips and Tricks
Ten Xcode Tricks Every Developer Should Know
To be productive and efficient, you need to know your tools. For a Swift or Cocoa developer, that means mastering Xcode. While Xcode is a complex piece of software with a fairly steep learning curve, the tricks listed in this episode should significantly boost your productivity.
1. Open Quickly
The Open Quickly command can be found in Xcode's File menu. The keyboard is your friend, though. Press Command + Shift + O to bring up the Open Quickly modal. You can search for files, types, methods, and functions.
The Open Quickly command has saved me countless hours and I use it dozens of times every single day. If Open Quickly is new to you, then I strongly recommend giving it a try.
2. Reveal in Project Navigator
The Reveal in Project Navigator command is a timesaver when you're working on large, complex projects with lots of files and groups. The command shows or reveals the file you're editing in the Project Navigator on the left. The default keyboard shortcut is Command + Shift + J.
3. Assistant Editor
The Assistant Editor is harder to find as of Xcode 11 even though it is incredibly useful. Press Control + Option + Command + Return to show the Assistant Editor on the right. Most developers leave the Assistant Editor underused. It is great for showing the counterpart of a file or for simultaneously working on the user interface and implementation of a view controller.
The Assistant Editor has a lot more uses, though. I use it often to find out where or how often a particular method is invoked. Place your cursor in the body of a method and select Callers from the Assistant Editor's menu at the top.
4. Jump to Method
When I'm browsing the implementation of a complex class or struct, I often have the need to quickly jump to a particular method or section of the implementation. This is very easy by pressing Control + 6 and typing the first few letters of what you're looking for.
5. Browse Documentation
No matter how experienced you are, the documentation is a developer's best friend. To quickly open Xcode's documentation browser and search for a particular type, method, or function, press Option and click the symbol you are interested in.
This also works for any symbols defined in the project. This is useful for teams that work on large, complex projects.
6. Edit All in Scope
Multiple cursors are great and every modern editor should include this feature. Xcode's code editor also includes this feature, but it is difficult to find and hard to use. In Xcode, the feature is better known as Edit All in Scope.
When you place the cursor on the symbol you are interested in, the code editor highlights every instance of the symbol in scope. Choose Edit All in Scope from the Editor menu or press Control + Command + E.
7. Git Blame
Apple made a subtle but noticeable change to Xcode's support for source control. You won't find the word blame anywhere in Apple's IDE. I suppose the word blame has a negative connotation.
It is still possible to use the
git blame command, though. Right-click the line of code you're interested in and choose Show Last Change For Line from the contextual menu. This brings up the commit that modified that line of code.
8. Code Review
Tower is my preferred Git client, but I have to admit that Xcode's built-in source control management has improved substantially over the years. The key advantage Xcode has over Git clients is that it is built into the code editor.
A few years ago, Apple renamed the Blame pane to the Authors pane. You can bring up the Authors pane by clicking the Adjust Editor Options button in the top right and choosing Authors from the menu or pressing Control + Shift + Command + A, one of the harder keyboard shortcuts.
This is just the start, though. When you click a commit in the Authors pane on the right, a contextual menu pops up. You can ask Xcode to show you the commit or open the commit in Xcode's code review editor.
9. Open in Assistant Editor
I discovered the next trick only a few months ago and was pleasantly surprised. Like most developers, I often use two editors side by side. This is useful for a range of reasons. What I most often want is use the Open Quickly command and open the file I'm searching for on the right of the editor.
We are currently browsing AppDelegate.swift. Let's say I want to open RootViewController.swift on the right. I can use the Open Quickly command to open RootViewController.swift. If I press return, Xcode opens the file in the main editor. By pressing Option + Return RootViewController.swift is opened in a new editor on the right.
10. Fancy Breakpoints
Breakpoints are indispensable for debugging problems, but having too many breakpoints can sometimes be counterproductive. You sometimes simply want to know that a code path is executed. You don't necessarily want to interrupt the process.
There is a neat trick I cover in detail in Debugging Applications With Xcode. Add a breakpoint by clicking the line number on the left of the editor. Right-click the breakpoint and choose Edit Breakpoint... from the contextual menu. Set Action to Sound and choose a sound from the list. You can optionally check Automatically continue after evaluating actions if you don't want the breakpoint to interrupt the process.
Every time the breakpoint is hit, Xcode plays the selected sound without interrupting the process. This is convenient and can be applied in a range of scenarios, for example, if you want to make sure that a code path is executed or if you want to know how often a code path is executed.
Learning about Xcode tricks may seem unimportant, but some of these tricks can save you countless hours and they significantly increase your productivity. What are your favorite tricks to speed up your work in Xcode. Share them on Twitter.