Default Xcode Shortcuts
- When the project grows, searching time for the file that we’re currently coding in Project Navigator increases. The day I learned the ⌘⇧J shortcut to jump to the current file in navigation, I had a smile on my face.
- Who doesn’t love to work with Assistant Editor in Xcode? Some of us feel disturbed when they reached to mouse while coding. So, moving the focus between Assistant and Main Editors as well as tabs has a shortcut ⌘J. It shows you a window that you can choose the focused editor by arrows. But there is one more shortcut which I find more useful is ⌃`. This allows you to move your focus directly to the next editor.
- Sometimes I found myself copying and pasting a block of code couple of lines up and down. Recently, I learned there are two shortcuts which most developers don’t use (at least I didn’t see anyone using lately). For moving the line up ⌥⌘[ and moving the line down ⌥⌘]
- Everyone knows ⌘⇧O to open file search bar in Xcode. If you’re working with Objective-C and Swift in the same project, you can search in Swift Generated Headers in this search. When search bar is open, press ⌘G to enable Swift generated headers. It’ll generate headers in Swift for Objective-C files.
- Let’s take a look at these shortcuts for opening/closing parts in Xcode that I’ve learned years ago from StackOverflow.
During debugging, when we stopped the running code with a breakpoint, we can use ⌘⌃Y to Step Over as well as ⌘Y to enable/disable all breakpoints.
Let’s focus on creating our own shortcuts. Most of us even don’t know that we can customize shortcuts in Xcode. Refactoring code is easier than ever with Xcode 9. And I’m not only talking about new renaming feature. I’m talking about all Refactor menu.
First, open Properties -like most of the macOS apps- using ⌘,. Switch to Key Bindings section from navigation. Choose All submenu. Now, you can see all shortcuts in there.
Below you can see all customized shortcuts that I’ve been using for some time. Some of them conflict with Xcode default shortcuts and I decided to remove default ones because I never use them. You’ll also see some empty ones. Those are the ones I’m not using, conflicting or pressing by mistake all the time like Print in the beginning.
You probably noticed that I changed the Rename shortcut to use same key combinations with other refactor methods.
I won’t get into details of LLDB debugger commands. I just want to suggest a good tutorial on how to use the commands and one great cheatsheet for LLDB commands. One thing I want to mention is that if you get the following error while trying to access frame or similar things
error: property ‘frame not found on object of type ‘UIView *’
error: 1 errors parsing expression
you should write expr import UIKit in LLDB command line. One way to execute this automatically is to create an auto-continue breakpoint in AppDelegate and add this command into Debugger Command action.
Other Tools and Frameworks
I’ve replaced Spotlight Search with Alfred on my mac and I’m really happy with all the features it has. Alfred has a Clipboard and Snippets features that I’m using all day long while coding. I’ve created some snippets according to my current iOS application development stack. For example, we’re using MVVM architecture and I have boilerplate code snippets for ViewModel, View, ViewController that I can easily use. You can reach my Alfred Snippets for Swift from here.
Command Line Tools & Aliases
- I like using Git from the command line instead of programs like SourceTree. I’ve been using Tig for that and I’m really happy so far. It’s easy & fast. Learning the tool can take some time but after you get used to it, you’ll see how easy to use Git.
- Also, we’re using branching model from Vincent Driessen at work. Of course, it has a tool that makes this usage easier. It’s called gitflow.
- Lastly, I’m using oh-my-zsh with some plugins ( git zsh-autosuggestions docker git-flow tig swiftpm sublime osx history dotenv). You can choose the plugins that suitable for your tech stack.
Third Party Libraries
Last But Not Least – OS-wide shortcuts
⌘⌥⎋ – Force Quit
⌘` – Change window for same application
Time is the most important thing in our lives. Increase your productivity. Work efficiently. Use one tip or all. Actually, customize those tips for yourself.
If you know cool shortcuts or other tools that boost your productivity, share it with me in the comments!
Command – ⌘
Shift – ⇧
Esc – ⎋
Ctrl – ⌃
Enter – ⏎