Reputation: 2858
I have the following code, for example:
[cardRegistrationVC setCancelBlock:^{
[weakSelf.navigationController popViewControllerAnimated:YES];
}];
When I apply clang-format on it, it turns into:
[cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }];
As you can see, code inside the block appears on the same line. But I should be always on a new line.
How to set up clang-format correct? My following settings file:
BasedOnStyle: LLVM
AllowShortIfStatementsOnASingleLine: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
IndentCaseLabels: true
ColumnLimit: 120
ObjCSpaceAfterProperty: true
KeepEmptyLinesAtTheStartOfBlocks: true
PenaltyBreakString: 1000000
SpacesInContainerLiterals: false
Upvotes: 13
Views: 4370
Reputation: 483
Just add this to the setting file(.clang-format).
ObjCBlockIndentWidth: 4
Then the block will like this.
[cardRegistrationVC setCancelBlock:^{
[weakSelf.navigationController popViewControllerAnimated:YES];
}];
Hope help you.
At the same time I would like add :
UseTab: Never
IndentWidth: 4
Upvotes: 9
Reputation: 2858
Finally I ended up writing blocks like this:
[cardRegistrationVC setCancelBlock:^{
[weakSelf.navigationController popViewControllerAnimated:YES];
}];
Empty line at the end works ok. Or you have to disable column limit:
#ColumnLimit: 120
Upvotes: 1