Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix code indentation in Xcode

Tags:

xcode

Once I start editing my code and adding for loops or if then statements my code indentation is whacked because the previous code maintains its former indentation instead of adjusting automatically.

In Visual Studio you can highlight code and select 'format selection' to fix these issues - is there anything similar in Xcode?

like image 218
Slee Avatar asked Aug 24 '10 16:08

Slee


People also ask

How do I change indentation in Xcode?

Choose Xcode > Preferences… from the menu bar (default shortcut: command-comma). Then click the “Text Editing” section. Then choose the “Indentation” tab.

How do I fix format in Xcode?

Xcode can fix this with one shortcut: select the code you want to fix, then press Ctrl+I to reindent it.

How do I indent all codes in Xcode?

Select the entire code and press control + I on mac to format your code. Select the code and press: ⌘ + ] for right move (indent)


1 Answers

Before Xcode 9 (for Xcode 9 see default shortcut below)

  1. select text
  2. right-click
  3. there's a "Re-indent selection" item in popup menu

In XCode 4 there is one more step:

  1. select text
  2. right-click
  3. Click on "Structure"
  4. there's a "Re-indent selection" and other options in popup menu

Or using the default shortcut:

  1. select text
  2. press ctrl + i
like image 161
Vladimir Avatar answered Sep 28 '22 12:09

Vladimir