As iOS developers, we spend most of our time at work in the Xcode. To put it into perspective - It's about 20–35 hours per week! What if I told you that you may use this time inefficiently, and you can optimise it?
Imagine having an elevator in your house, but still using stairs to get to the top floor.
At the end of the day, you'll reach the same floor, but at the cost of time and exhaustion. The same is applicable to using Xcode without shortcuts.
In this article, I'll show you a few Xcode shortcuts that will boost your productivity and elevate your skills in writing code.
We'll separate them by Project View and Navigation, Code Editing, and Project Build sections. Some of them might be well-known, and some - can be new to you, but I'm sure all of those mentioned are essential to every iOS developer.
Plus, there's a very helpful bonus at the end of the article 👀
First things first, let's agree on the dictionary of the symbols. In this article, I'll follow this setup:
⌘ – Command key
⌃ – Control or Ctrl key
⌥ – Option or Alt key
⇧ – Shift key
Project View and Navigation
In this section, we'll focus on the shortcuts that will help you to navigate through your Xcode project and understand its file system way faster than you used to.
The first one is ⌘ + ⇧ + O. To open a file by its name, just press this combination, type the filename, and you'll see a list of options matching your input.You can search by class/struct name and methods declaration.This is the fastest way of getting around the big projects when trying to find something, especially when onboarding into a new project.
The next one is ⌘ + J - focus on a file in the navigator. It's very helpful while working on projects with complex structures - you can easily end up in some unknown location, and this shortcut will show you exactly where you are right now.
⌘ + N - create a new file. A common shortcut for all IDEs, but in combination with the previous one, you can create a new file in the right place of your project very fast.
⇧ + ⌘ + Y - show/hide debug area. Also comes in very handy for quickly accessing the debug area view.
⌘ + ⌥ + Enter - toggle SwiftUI Preview/Canvas. While working with SwiftUI, this one is helpful to toggle the additional Previews view when needed.
^ + ⌘+ J - Jump to the definition. After selecting a property or function, just use this shortcut, and it will navigate you to the definition of the selection.
⌘ + ⌃ + left/right arrows - jump between the previous and next opened file.
⌘ + ⇧ + 0 (zero) - show a documentation view. I encourage you to use this one from time to time or when dealing with some unknown Swift issues, Apple's documentation is very user-friendly and easy to navigate through.
Code Editing
Now we'll focus on how to boost your code editing with shortcuts.
⌘ + ⌃+ E - Select all in scope. Very useful shortcut for refactoring small chunks of code in a local scope. Let's say you've misspelled your property name, and you want to fix it quickly in all local-scope usages. You can do so by selecting a word and using this shortcut:
⌘ + ⌥ + E - find in the current file. Just select a word and press this shortcut to jump to the next usage of this word.
But be careful, this shortcut is case-insensitive and matches by parts, not the whole word.
⌃ + I - Re-indent code. After making some changes to your functions, you may notice that code indentation can mess up. Use this shortcut to quickly fix your code.
⌘ + ⌥ + Up/Down arrows - fold/unfold method or class. It will cover the selected part of the code. Very helpful to use this in big and complicated parts of code, just in order to focus on what's important right now.
⌘ + ⌥ + / - create a documentation. It just pastes a documentation template right above the selection, which is way faster than writing it all by yourself.
Project build
As for the project build shortcuts, I consider these most helpful:
- ⌘ + R - run current target
- ⌘ + B - build current target
- ⌘ + U - build and run testing target. Add ⇧ (⌘ + ⇧ + U) to just build without running. Or add ⌃ (⌘ + ⌃+ U) to skip building when it's not needed
- ⌃ + ⌥ + ⌘ + G -re-run a previous test case. Very helpful while fixing just one problematic test. If your last testing action was running the whole class, it will run the whole class again
- ⌘ + ⇧ + K - clean build
Bonus time!
For a quick multiline change in your code, you can use ⌃ + ⇧ + up/down arrows. This way, you will activate a multiline cursor, which can be very handy for refactoring chunks of code without repetitions. And, to make it sound even better, you can use mouse clicks to select the specific parts of lines to edit!
I can guarantee that after using it a few times, you'll love it and will not imagine your Xcode development without this shortcut!
And also, as a bonus-bonus, you can change and create your own shortcuts in Xcode. To do so, go to Xcode → Settings → Key Bindings.
Be careful not to use some macOS system shortcuts though, because the OS will treat it with a bigger priority
In conclusion, I'd say that the usage of the Xcode shortcuts is a pretty good marker of how proficient a developer is. After hosting multiple iOS job interviews with live coding/debugging sessions, I always paid attention when an interviewee was using them. It shows that the person is not totally new to iOS development and is interested in becoming more proficient by learning how to use a tool a bit more than just creating a project and being able to run it.
And that's it! I hope you've learned something new from this article and that I've helped you become an even more productive iOS Developer than you were before.
Have I missed some interesting shortcuts? Let me know in the comments, let's learn together!
Top comments (0)