一、整理了objclean调查结果中多数人的代码风格,http://objclean.com/survey.php
1.function

2.property declare

3.variable declare

4.protocol

5.condition


二、使用Clang-Format
Clang-Format是一款Xcode的代码格式化插件,github项目地址https://github.com/travisjeffery/ClangFormat-Xcode,安装使用过程如下:
1.通过Package Manager搜索并安装插件

2.在工程目录下放置.clang-format的配置文件,可以自己调整相应值,示例配置文件如下:
# 基础样式
BasedOnStyle: LLVM
# 缩进宽度
IndentWidth: 4
# 圆括号的换行方式
BreakBeforeBraces: Attach
# 支持一行的if
AllowShortIfStatementsOnASingleLine: true
# switch的case缩进
IndentCaseLabels: true
# 针对OC的block的缩进宽度
ObjCBlockIndentWidth: 4
# 针对OC,属性名后加空格
ObjCSpaceAfterProperty: true
# 每行字符的长度
ColumnLimit: 0
# 注释对齐
AlignTrailingComments: true
# 括号后加空格
SpaceAfterCStyleCast: false
# 不在小括号里加空格
SpacesInParentheses: false
# 不在中括号里加空格
SpacesInSquareBrackets: false
3.安装成功后会在xcode–>Edit里出现选项

网友评论