【问题标题】:How to format objective-c block with clang-format?如何用clang-format格式化objective-c块?
【发布时间】:2014-11-17 09:51:41
【问题描述】:

我有如下代码,例如:

[cardRegistrationVC setCancelBlock:^{
  [weakSelf.navigationController popViewControllerAnimated:YES];
}];

当我对其应用 clang-format 时,它变成:

[cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }];

如您所见,块内的代码出现在同一行。但我应该总是换行。

如何正确设置clang-format?我的以下设置文件:

BasedOnStyle: LLVM
AllowShortIfStatementsOnASingleLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
IndentCaseLabels: true
ColumnLimit: 120
ObjCSpaceAfterProperty: true
KeepEmptyLinesAtTheStartOfBlocks: true
PenaltyBreakString: 1000000
SpacesInContainerLiterals: false

【问题讨论】:

    标签: objective-c xcode clang-format


    【解决方案1】:

    只需将其添加到设置文件(.clang-format)中即可。

    ObjCBlockIndentWidth: 4
    

    那么方块就会变成这样。

     [cardRegistrationVC setCancelBlock:^{
         [weakSelf.navigationController popViewControllerAnimated:YES];
     }];
    

    希望能帮到你。

    同时我想补充:

    UseTab: Never
    IndentWidth: 4
    

    【讨论】:

      【解决方案2】:

      最后我写了这样的块:

      [cardRegistrationVC setCancelBlock:^{   
        [weakSelf.navigationController popViewControllerAnimated:YES];
      
      }];
      

      最后的空行可以正常工作。 或者您必须禁用列限制:

      #ColumnLimit: 120
      

      【讨论】:

        猜你喜欢
        • 2017-10-30
        • 1970-01-01
        • 2019-06-18
        • 1970-01-01
        • 1970-01-01
        • 2021-01-11
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        相关资源
        最近更新 更多