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:

  1. 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.

  2. Move Line Down
    Using 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.

  3. Multiple Cursors
    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.

  4. Show Group Files
    We can jump to any file using Control(⌃) + 5 from the jump bar or View -> Editor -> Show Group Files from the menu bar.

  5. Show Document Items
    We can jump to a method or variable name from the jump bar by Control(⌃) + 6 or from the menu bar using View -> Editor -> Show Document Items.

  6. Open Quickly
    Using 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....

  7. Indentation
    Using Control(⌃) + I we can re-indent the selected code. This setting is also available via Editor -> Structure -> Re-indent.

  8. Spell Check
    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.

  9. Variable Renaming
    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.

  10. Extracting Methods
    Extract to Method is 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!