加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Objective-C Clang-Format方法Brace Break

发布时间:2020-12-14 19:06:12 所属栏目:百科 来源:网络整理
导读:我正在为我的Objective-C项目使用clang-format,但是我在设置它时遇到了困难. 这是我想要的结果: - (NSString *)someMethod{ return @"My String";} 这是格式化后的实际结果: - (NSString *)someMethod { return @"My String";} 这是我的.clang格式文件: B
我正在为我的Objective-C项目使用clang-format,但是我在设置它时遇到了困难.

这是我想要的结果:

- (NSString *)someMethod
{
  return @"My String";
}

这是格式化后的实际结果:

- (NSString *)someMethod {
  return @"My String";
}

这是我的.clang格式文件:

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

我需要更改什么设置才能让格式化程序在Objective-C方法的开头括号之前放置换行符?

解决方法

对于你的clang格式的任何微调你最好永远不要使用BasedOnStyle因为这对我来说只是创建随机和难以调试的结果.

最简单的方法可能是设置:BreakBeforeBraces:Custom然后按照你在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读