Xcode插件Clang Format使用

1 . 使用插件管理工具Alcatraz安装Clang format插件

2 . 打开终端,cd到工程文件夹目录,然后输入vi .clang-format创建隐藏文件.clang-format,并输入以下格式文件:(可根据自己公司的要求进行定制)

# 基础样式
BasedOnStyle: LLVM

# 缩进宽度
IndentWidth: 4

# 括号的换行方式(Attach,Stroustrup, Allman-所有大括号都另起一行)
BreakBeforeBraces: Attach

# 支持一行的if
AllowShortIfStatementsOnASingleLine: false

# 是否允许循环单行
AllowShortLoopsOnASingleLine: false

# switch的case缩进
IndentCaseLabels: true

# 针对OC的block的缩进宽度
ObjCBlockIndentWidth: 4

# 针对OC,属性名后加空格
ObjCSpaceAfterProperty: true

# 每行字符的长度
ColumnLimit: 0

# 注释对齐  
AlignTrailingComments: true  
  
# 括号后加空格  
SpaceAfterCStyleCast: true

3 . :wq保存并关闭
4 . 打开Xcode,选择Edit-ClangFormat-File (即让clangformat插件使用我们刚才定制的格式文件)

补充:设置格式化快捷键
1.打开 **系统偏好设置 | 键盘 | 快捷键 | 应用快捷键 ,单击 + 添加应用程序快捷键,比如control f,如下图:

Xcode插件Clang Format使用_第1张图片
屏幕快照 2016-09-06 下午4.27.24.png

注意: 菜单标题 项目,不可以输入错误!!!!
然后在工程中,选中代码按 control f组合快捷键即可将代码格式化为自己定制的格式。

:可配置快捷键的项目有如下三个:

Format File in Foucs
Format Selected Text
Format Selected Files
屏幕快照 2016-09-06 下午4.31.36.png

你可能感兴趣的:(Xcode插件Clang Format使用)