Leave a rating/review
Xcode has a number of keyboard shortcuts that you can use to accelerate your iOS development.
Actually, you’ve already learned about six shortcuts throughout this couse:
- Cmd+B, which builds your app.
- Cmd+R, which runs your app.
- Cmd+U, which unit tests your app.
- Option+Cmd+P, which previews your app in the SwiftUI canvas.
- Option+Cmd+[, which moves an line of code up, which is especially useful when working with view modifiers.
- And finally, Option+Cmd+], which moves a line of code down.
In this episode, we’re going to review some more handy shortcuts that you’ll find useful in your day-to-day work as an iOS developer. Let’s dive in!
I have BullsEye pulled up here, where we left if up in the previous episode.
Let’s start by learning some keyboard shortcuts that you can use to navigate Xcode’s user interface itself.
Try pressing Press Shift Cmd Y, which shows and hides the debug console. Think back to earlier in this course, when you used the print function to print a message to the console - that’s where that shows up. This is also used when you’re debbuging your apps with Xocde’s debugger - this is where you can inspect the app’s variables. Ray Wenderlich team member Jack Wu has made this an easy one to remember - Y is my code not working. Use Shift Cmd Y to hide the debug console again.
You manage the Navigator pane on the left with Command and the number keys. Cmd 0 opens and closes the Navigator pane, and Cmd 1 to 9 goes straight to the relevant navigator. (Demo 1-9)
Command 5 will show you your current issues, and command 1 takes you back to the Project Navigator.
You manage the Utilities pane on the right with Option Command and the number keys. Option Command 0 opens and closes the pane.
This is mostly useful in the Canvas. Inside TextViews.swift, click on the “You scored 200 points” label, and open up the Attributes Inspector with Option+Cmd+4. You’ll see here you can tweak some of the properties here in a visual manner.
While you’re here, it’s often useful to show or hide the canvas. Do this with Option+Cmd+Return. Each time you press this it will toggle showing or hiding the canvas.
Notice that at the top of your editor, Xcode provides a jump bar that lets you quickly switch between files in your project. This is especially useful if you’ve hidden your project navigator with Cmd+0.
In addition between navigating between files in the jump bar, you can also quickly navigate within a file. In TextViews.swift, this makes easy to jump straight to the view you want to edit rather than scrolling through the entire file. The larger your files get, the more useful this is.
As you might imagine, there are shortcuts to use the jump bar as well. We use the Control modifer and the number that represents selecting the breadcrumb level we’re after
Ctrl 6 gives us the drop down so that we can arrow to the scene we want.
Ctrl 5 gives us the drop down of files in the current directory.
Ctrl-4 lets us nagivate through the entire project.
Ctrl-2 and Ctrl-3 are shortcuts to the back and forward buttons, which let you navigate through your most recent files.
And Ctrl-1 is a shortcut to the main menu that lets you navigate through recent files, and other files you’re likely to want to open.
Let’s try something new.
Shift Command O is Open Quickly and brings up a dialogue where you can enter the name of the file. You’ll probably use this shortcut a lot. If you’re working on a huge project, then you probably won’t even remember the name of the file, so you only need to type in part of it.
Type in t-e-x, which brings up TextViews.swift and press return. You’re now editing that file.
To see all the keyboard shortcut bindings, press Cmd , to bring up the preferences, and choose Key Bindings. You can now see all the shortcuts on all the menus. And you can also change them here if you want to.
I hope you find these Xcode shortcuts helpful! I definitely recommend taking a bit of time to practice them; once you have these in your muscle memory, they’ll be a huge timesaver for you.