如何更改Xcode 4.5中的默认代码缩进?

Dan*_*iel 18 indentation xcode4

当我创建一个新的视图控制器时,它的默认代码缩进样式看起来像

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

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

我可以更改任何设置,以便默认代码缩进如下所示

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

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

rob*_*off 32

从菜单栏中选择Xcode> Preferences ...(默认快捷键:command-comma).然后单击"文本编辑"部分.然后选择"缩进"选项卡.将"缩进宽度"设置为2.

Xcode首选项

您可以通过在Project Navigator中选择项目,然后在File Inspector的"Text Settings"部分中设置"Indent"值来更改一个项目的缩进宽度:

在此输入图像描述

您可以通过选择代码并从菜单栏中选择"编辑器">"结构">"重新缩进"(默认快捷键:control-i),让Xcode使用新的缩进宽度重新格式化现有代码.

  • 我之前尝试过这个,但它不起作用.当我创建一个新项目或一个新的.m文件时,默认缩进保持不变. (2认同)