问题 如何使用clang格式格式化objective-c块?


我有以下代码,例如:

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

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

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

如您所见,块内的代码出现在同一行。但我应该总是站在新的一条线上。

如何设置clang格式正确?我的以下设置文件:

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

10679
2017-09-23 08:55


起源



答案:


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

ObjCBlockIndentWidth: 4

然后块就会这样。

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

希望能帮助你。

同时我想补充一下:

UseTab: Never
IndentWidth: 4

8
2018-03-19 17:37





最后我最终编写了这样的块:

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

}];

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

#ColumnLimit: 120

1
2017-11-20 08:09