Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default code indentation in Xcode 4.5?

When I created a new view controller, its default code indentation style looks like

- (void)viewDidLoad
{
    [super viewDidLoad];
  // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

Can I change any settings so the default code indentation looks like below

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}
like image 648
Daniel Avatar asked Dec 29 '12 03:12

Daniel


People also ask

How do I show indentation in Xcode?

In Xcode 10, if you press Command and hover over the structure it will show what is desired.

How do I fix indentation in Swift?

Xcode tip #21: If you've copied code from elsewhere, such as Hacking with Swift or Stack Overflow, there's a good chance you'll paste in something with incorrect indentation. Xcode can fix this with one shortcut: select the code you want to fix, then press Ctrl+I to reindent it.

How do I fix tabs in xcode?

You need to open Xcode's Navigation preferences, and for “Navigation Style” select “Open In Place”. The new “inner tab bar” will disappear, and the previous tab behavior (and shortcuts!) will be restored.


1 Answers

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

Xcode preferences

You can change the indentation width for just one project by selecting the project in the Project Navigator, then setting the “Indent“ value in the “Text Settings” section of the File Inspector:

enter image description here

You can ask Xcode to reformat existing code with the new indentation width by selecting the code and choosing Editor > Structure > Re-Indent from the menu bar (default shortcut: control-i).

like image 99
rob mayoff Avatar answered Nov 02 '22 22:11

rob mayoff