Whether beginner, intermediate or advanced developer, we all want to achieve our task by developing workable code. We want to accommodate changes soon to ensure efficiency too. But what if we are not too familiar with the IDE? We land up doing things that take much more time & effort than required.
Xcode has a wide variety of these shortcuts, so here are some of them which helped us achieve our tasks faster:
Move Line Up
Command(⌘) + Option(⌥) + [shifts the selected piece of code upward, to rearrange the current code. Alternatively, we can also use the same shortcut via
Editor -> Structure -> Move Line Up.
Move Line Down
Command(⌘) + Option(⌥) + ], we can move the selected code to a downward line, thus rearranging it. Alternatively, we can also use the same shortcut via
Editor -> Structure -> Move Line Down.
When we want to have many lines edited with the same text, we need cursors at all those points at the same time. To get multiple cursors, we can use any of these to go to the appropriate location:
Shift(⇧) + Control(⌃) + Click Shift(⇧) + Control(⌃) + Up Arrow(↑) Shift(⇧) + Control(⌃) + Down Arrow(↓) Option(⌥) + Shift(⇧) + Drag
This gets all cursors blinking. Now whatever we type will get typed at all cursors together.
Show Group Files
We can jump to any file using
Control(⌃) + 5from the jump bar or
View -> Editor -> Show Group Filesfrom the menu bar.
Show Document Items
We can jump to a method or variable name from the jump bar by
Control(⌃) + 6or from the menu bar using
View -> Editor -> Show Document Items.
Command(⌘) + Shift(⇧) + O, we can search any file or code through the search bar. Another way to access this shortcut from the menu bar is by
File -> Open Quickly....
Control(⌃) + Iwe can re-indent the selected code. This setting is also available via
Editor -> Structure -> Re-indent.
We can check typos for a programming language having concatenated words. It functions in the same way as to spell check settings in MS Office and the like. So to put it on, go to
Edit -> Format -> Spelling and Grammar -> Check Spelling While Typing. As you turn on this setting, all the names that have spelling errors get underlined in red.
To rename a variable within one file, select the variable name and click
Control(⌃) + Command(⌘) + E. All occurrences change at once.
Note: To change the variable name throughout the project, right-click the name of the variable and select
Refactor -> Rename.It shows all occurrences of the variable throughout the project. We can rename it at one go by typing in the new name. You can also untick the file contents you don't want to rename, i.e., selective file renaming is possible.
Extract to Methodis an easy way to extract some lines of code from one method to an independent method. Right-click the selected code and then choose
Refactor -> Extract to Method.
We only need to type in a suitable name for this method, and it automatically creates a method with the necessary parameters.
We hope these shortcuts have given you an insight into the various hidden provisions by Xcode. These essentially help when the project size is large, and many programmers develop it over a considerable span. They'll also save you some time which you can spend on boilerplate code henceforth!