一、整理了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里出現選項