I'm working with clang-format for my Objective-C project, but I'm having difficulty setting it up properly.
Here's my desired result:
- (NSString *)someMethod
{
return @"My String";
}
Here's the actual result after formatting:
- (NSString *)someMethod {
return @"My String";
}
Here's my .clang-format
file:
BasedOnStyle: WebKit
AlignTrailingComments: true
ColumnLimit: 120
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
TabWidth: 2
UseTab: Never
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: true
AfterExternBlock: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
What setting do I need to change to get the formatter to put a line break before the opening brace of an Objective-C method?
For any fine-tuning of your clang-format
you are much better off never to use BasedOnStyle
because that for me just creates random and hard to debug results.
Easiest way to do this would be probably to set: BreakBeforeBraces: Custom
and then set everything up the way you want it in as it says in the documentation:
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With