Favorite Xcode shortcuts
Introduction
Oh Xcode, what a love-hate relationship I’ve got with you. So many good things in that IDE, yet so many shitty things all at once. However, love it or hate it, Xcode is our bread and butter, and unless you work with a very specific workflow, you’ll be spending most of your time in Xcode. So why not make the best of it and learn some shortcuts to make your life easier? Here are a few of the shortcuts I use on a daily basis. I hope you’ll find them useful too! I will be referring to their default key combinations, but you can always change them in the preferences (I have!)
Command palette
If you’ve used something like VSCode or an IntelliJ IDE, you’re probably familiar with the command palette. It’s a quick way to access any command in the IDE. In Xcode, you can access it with Cmd + Shift + A
. The reason I’m starting with this one is that it can honestly replace almost all of the following ones. I use this command all the time, to do things like reset package caches, generate initializers, or honestly anything else. It’s a great way to discover new features in Xcode too. I’ve remapped it to Cmd + Shift + P
, so my muscle memory doesn’t go away when I spend time in VSCode writing Fastlane stuff (if you haven’t seen it yet, this is how I work on my Fastlane stuff.)
Open quickly
If you’ve watched any YouTube tutorial, you’ve undoubtedly seen the person presenting using this shortcut. It’s one of those “once you start using it you will never stop using it”. All it does is give you a quick search bar to open any file in your project. It’s a great way to navigate your project without having to use the project navigator. You can access it with Cmd + Shift + O
. I’ve remapped it to Cmd + P
, because I use it that much.
Edit all in scope
You know when you’re refactoring and you’ve realized that you’ve named a variable wrong? How could it possibly be called first_name
when it obviously should be firstName
? Well, if that variable is also used in 10 more places in the file, you can use Cmd + F
to find them all and replace them one by one, or use the big bulky refactor from the above-mentioned command palette, or you can use Cmd + Ctrl + E
to edit all in scope. It’s a great way to quickly change a variable name, or a method name, or anything else that you want to change in a file. It’s a great way to keep your code consistent and clean.
The important bit here is that this edit all is in scope. So if you’re inside a method, it’ll only rename inside that method. If you’re at the top level of the file, it’ll rename everything in the file.
Reveal in project navigator
This is one of those that I couldn’t believe that I’d gone so long without knowing. You know how you’re working on a file, and you want to see where it is in the project navigator? You can right-click on the file and select “Reveal in project navigator”, or you can use Cmd + Shift + J
to do it. It’s a great way to quickly see where a file is in your project, and it’s a great way to keep your bearings in a large project. I use it all the time when I’m working on a new project and I’m not sure where everything is.
Bonus one - Format File by SwiftFormat
If you’ve known me for more than 20 minutes, you’ve heard me rave about SwiftFormat. It’s my most used tool ever (the rest are here), and it’s the first thing I add to any project I’m working on.
You can use it from the command line, or you can use it as a pre-commit hook, but you can also use it as an Xcode extension. I’ve chosen the latter, and remapped the key combination to Shift + F3
, and use that about a thousand times a day. It’s a great way to keep your code consistent and clean, and it’s a great way to make sure that you’re not spending time on formatting your code, but on writing it.
Conclusion
There are a million more shortcuts in Xcode, and I’m sure you’ve got your own favorites. Almost all of them can be accessed from the command palette, so I’d recommend starting there. I hope you’ve found these useful, and I’d love to know what your favorite shortcuts are! Let me know on socials!