Make good use of Xcode shortcuts to increase your productivity

Make good use of Xcode shortcuts to increase your productivity

If you are an iOS, macOS, tvOS, or watchOS developer, Xcode may be the IDE you use most often.

最后更新 6/22/2021 10:57 PM
沙漠尽头的狼
预计阅读 9 分钟
分类
share
标签
Xcode
  • 13 Xcode Shortcuts to Boost Your Productivity
  • Original link: betterprogramming.pub/13-xcode-shortcuts-to-boost-your-productivity-329c90512309
  • Original author: Anupam Chugh
  • Translator: Wolf at the end of the desert, Baidu Translation (Translation Support)

Developers often spend a lot of time on IDEs. If you are an iOS, macOS, tvOS, or watchOS developer, Xcode may be the IDE you use most often.

I often hear developers making excuses for not learning Xcode shortcuts when they first started using Xcode. In their defense, they had one valid argument:

_If you don't remember the shortcut keys, using the mouse can at least help you get the job done quickly. In addition, learning shortcuts is like an extra learning curve, especially when you are just starting to learn.

To explain the impact of keyboard shortcuts on developer productivity, I will share the results of a study with them:

If your job requires you to use the IDE for eight hours a day, using keyboard shortcuts ** can save eight working days per year **.

Eight days is a long time. In just a few hours, you can use Xcode's shortcuts skillfully, saving an extra week. The efficiency of using shortcuts will allow you to focus on the larger task at hand and speed up your development and workflow.

In the next few sections, we will introduce many Xcode keyboard shortcuts that I find useful. I hope they can also help you improve development efficiency.

You don't need to remember this list. I added a named shortcut next to the symbol:

你不需要记住这张清单。我在符号旁边添加了命名的快捷方式。

...

1 Basic Shortcuts

The following is a list of the most commonly used shortcut keys in Xcode:

  • Build: + B
  • Run: + R
  • Test: + U
  • Stop0:+ .
  • Clean: ++ K
  • Clean the build folder: +++ K
  • Open quickly: ++ O
  • Code completion: + space

2 Assistant Editors Shortcuts

Xcode 11 brought many changes to their auxiliary editor. You can now run multiple editors as needed, switch focus modes on the current editor, or focus the current editor while hiding other editors. In addition, a new button has been introduced to set the position of the secondary editor relative to the current editor.

2.1 Add a secondary editor

Use the following shortcuts to add secondary editors. If in focus mode, the new editor will not be reflected on the screen.

** Shortcut key: ++ T**

(Control + Command + T)

通过将鼠标移动到“Add New Editor”按钮上并按住Option键,我们可以将新编辑器的位置切换到右侧或底部。

2.2 Focusing current editor

To hide all editors except the current editor, use the following set of keys:

** Shortcuts: +++*

(Shift + Control + Command + Enter)

2.3 Opening a file manually in assistant editor

Xcode 11 辅助编辑器的一个重大变化是没有手动操作选项。要在辅助编辑器中打开目标文件,请执行Shift + Command + O以快速打开,并在选择文件的同时按Option键,如图所示:

** shortcut key: ++ O followed by *

2.4 Switch between different editors (Navigation across editors)

When you use multiple auxiliary editors and need to switch between them, using the trackpad may not be as convenient. Here are a few shortcuts that allow you to easily switch between multiple editors:

** Highlight editor: + J**

(Command + J)

当前编辑器高亮显示后,可以使用方向键在辅助编辑器之间切换,并在新编辑器上按Return键使其成为活动编辑器。

3 Fix all errors in scope (Fix All Errors In-Scope)

I often encounter scenarios where Xcode throws a lot of errors at me, especially those related to Swift syntax-which is common when migrating across versions.

Fortunately, the Fix-it All option is effective at solving most common errors and saves us a lot of time, especially on large projects.

** Shortcut key: +++ F**

(Control + Option + Command + F)

4 Multiple Cursors on Multiple Selections

Typically, multiple cursors are needed to avoid typing/copying the same content in different lines. We can select the next word that appears by selecting the current word and pressing Alt + Command + E. This will place multiple cursors on the word and allow us to edit them simultaneously.

** Shortcut key: ++ E**

(Option + Command + E)

To select the previous reference, use Shift + Option + Command + E.

5 Refactor All In Scope

Refactoring is inevitable. This makes editing variables and methods within scope a key tool. The following shortcuts allow us to edit everything in scope simultaneously:

** Shortcut key: ++ E**

(Control + Command + E)

6 Jump to Method

To view the outline of the file, and all the methods, just press Command + 6. It opens a form where you can search for the desired method and jump directly to it.

** Shortcut key: + 6**

(Control + 6)

7 Jump to Definition

Starting from Xcode 9, the "Command + click" shortcut key will not directly allow you to jump to definitions. Instead, it displays a pop-up prompt with a list of options. To jump directly to definitions without displaying pop-up windows, use the following shortcut keys:

** Shortcut key: ++ J**

(Control + Command + J)

8 Fold and Unfold Methods

When the file size exceeds the limit (which ideally should not be), there is a convenient shortcut that lets you collapse code and collapse all methods/selected methods.

It places a code area on each enclosed block. Here are shortcuts for different situations:

** Fold all: +++ ←**

(Shift + Option + Command + Left Arrow)

** Expand all: +++ →**

(Shift + Option + Command + Right Arrow)

** Fold the current block: ++ ←**

(Option + Command + Left Arrow)

[6.gif]

9 Close tab (Closing Tabs)

Xcode has many shortcuts that let you choose which tab to close. You can close the current tab, or close other tabs. The shortcut keys for each operation are given below:

** Close tab: + W**

(Command + W)

** Close other tabs: ++ W**

(Command + Option + W)

...

10 Reorder Statements

To change the order of statements and move them to another location, use the following shortcut keys:

** Shortcuts: ++ ( ] or [ )**

(Command + Option + Square Brackets)

11 Find Call Hierarchy

To quickly find the call hierarchy for the selected symbol (whether it is a method or an instance), just use the following shortcuts. It opens the call hierarchy in the project navigator.

** Shortcut key: +++ H**

(Shift + Control + Command + H)

...

12 Global Search and/or Replace

The Xcode IDE has the ability to conduct fast global searches and even the ability to replace symbols anywhere (handle with care).

** Search throughout the project: ++ F**

(Shift + Command + F)

** Search and replace throughout the project: +++ F**

(Shift + Command + Option + F)

13 SwiftUI Previews

Swift UI has changed the way we think and build UIs. Using the built-in canvas preview in Xcode, it becomes much easier to build the UI from code or directly from the preview. Shortcuts are just the icing on the cake to speed up the development process.

13.1 Toggle canvas

This is a convenient shortcut if you want to quickly build prototypes in your code without letting real-time previews distract you.

** Shortcut key: ++*

(Option + Command + Enter)

** Continue automatic preview **

Automatic previews are usually paused and require us to manually resume them. Xcode 11 has a shortcut key that achieves this goal.

** Shortcut key: ++ P**

(Option + Command + P)

14 Minimap Shortcuts

Xcode 11 gave us Minimap. There is a much-needed code outline view on the right side of the IDE. By moving the mouse over it, you can navigate to any part of the code.

Among the important shortcuts, one switches the Mini Map view, and the other displays an outline of all properties, methods, classes, and code blocks in the file:

** Switch Minimap: +++ F**

(Shift + Control + Command + F)

*Minimap outline: ++

(Shift + Control + Command)

conclusion

We quickly browsed through many Xcode shortcuts that can greatly increase productivity and speed. Xcode11 introduces some convenient utilities and shortcuts that will just help you speed up your work.

For developers who are just starting to use shortcuts, I suggest taking it slow. Select some shortcuts and include them in your daily use cases to build muscle memory. Trying to remember everything at once is not the best way to master keyboard shortcuts.

That's all for this article-thank you for reading!

Keep Exploring

延伸阅读

更多文章