你如何调整Xcode的Objective C参数的自动缩进?

the*_*ory 6 formatting objective-c indentation auto-indent xcode4

这是我的iOS应用程序的一小段代码:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you like my hat?"
                                                    message:@"If so, please help spread the word by rating our app now?"
                                                   delegate:nil
                                          cancelButtonTitle:@"No Thanks"
                                          otherButtonTitles:@"Sure!", @"Maybe Later", nil
                          ];
Run Code Online (Sandbox Code Playgroud)

为什么Xcode缩进行如此血腥?作为一个旧的Perl,Ruby和JavaScript猴子,我更倾向于手动缩进它,如下所示:

    UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle:     @"Do you like my hat?"
        message:           @"If so, please help spread the word by rating our app now?"
        delegate:          nil
        cancelButtonTitle: @"No Thanks"
        otherButtonTitles: @"Sure!", @"Maybe Later", nil
    ];
Run Code Online (Sandbox Code Playgroud)

所以参数名称和值都是左对齐的,并且只缩进一个级别(对我来说是4个空格).这使用了更少的屏幕空间,而且我不太可能在MacBook Air上处理包装线(这使得最右边的缩进内容甚至更难阅读).

但是,我认为Apple更喜欢第一种方法,因此有Xcode缩进.还是有吗?

所以我有两个问题:

  • 您更喜欢在Objective C代码中缩进方法参数?
  • 你如何调整Xcode以使用您喜欢的缩进样式进行格式化?

不试图在这里开始圣战; 我更喜欢Objective-C程序员中最好的做法,Xcode如何帮助实现这些做法,并找出Xcode是否有充分理由采用默认方式.


更新:评论者和答案指出默认格式在冒号处对齐参数.我应该记得在张贴之前,因为我当然注意到了它,当最长的项目没有缩进时,它看起来很漂亮.但我发现,通常情况下,最长的项目缩进很多.例如:

UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Do you like my hat?"
                                message:@"If so, please help spread the word by rating our app now?"
                               delegate:nil
                      cancelButtonTitle:@"No Thanks"
                      otherButtonTitles:@"Sure!", @"Maybe Later", nil
                      ];
Run Code Online (Sandbox Code Playgroud)

这是为什么?即使我希望它们在冒号处对齐(​​我经常手工格式化它们),但是将它们缩进这么多似乎很愚蠢.为什么它坚持缩进开放结肠的水平?为什么不只是一个缩进级别,结束括号,以显示缩进"阻止"的结束?例如:

UIAlertView *alert = [[UIAlertView alloc]
        initWithTitle:@"Do you like my hat?"
              message:@"If so, please help spread the word by rating our app now?"
             delegate:nil
    cancelButtonTitle:@"No Thanks"
    otherButtonTitles:@"Sure!", @"Maybe Later", nil
];
Run Code Online (Sandbox Code Playgroud)

这似乎是比Google风格指南的线长建议更好的默认值,不是吗?

有没有办法调整Xcode以这种方式格式化参数?

Jus*_*tin 5

1)当给出多个参数时,Objective-c缩进约定在冒号处对齐.

功能:

- (void)functionWithOne:(NSString *)one two:(NSString *)two tree:(NSString *)three;
Run Code Online (Sandbox Code Playgroud)

必须格式化为:

- (void)functionWithOne:(NSString *)one 
                    two:(NSString *)two 
                  three:(NSString *)three;
Run Code Online (Sandbox Code Playgroud)

我来自Java,一开始我很难习惯.但尝试不同几次后,这真的是最好的方式.

2)我不认为(我不确定)你可以在xcode中改变它.Apple的惯例非常清楚它是如何实现的.

编辑:调用.我个人从第一个参数开始并将其余部分对齐如下:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Do you like my hat?"
                                                message:@"If so, please help spread the word by rating our app now?"
                                               delegate:nil
                                      cancelButtonTitle:@"No Thanks"
                                      otherButtonTitles:@"Sure!", @"Maybe Later", nil];
Run Code Online (Sandbox Code Playgroud)