1,最近项目代码要求规范化,在网上找了个Xcode插件:Clang Format ,下载地址:https://github.com/travisjeffery/ClangFormat-Xcode

2,设置快捷键:系统偏好设置 -》键盘-》快捷键-》应用快捷键-》+

应用程序里选择:Xcode,菜单标题:Format Selected Files , 键盘快捷键选择:ctr + \
应用程序里选择:Xcode,菜单标题:Format File in Focus, 键盘快捷键选择:car + cmd + \

3, 选择的格式不是我们想要的,和iOS的编码规范还是有一定差别的,自定义我们自己的格式吧

  • 创建  _clang-format 文件,内容如下:
# 基础样式

BasedOnStyle: LLVM

# 缩进宽度

IndentWidth: 

# 圆括号的换行方式

BreakBeforeBraces: Attach

# 支持一行的if

AllowShortIfStatementsOnASingleLine: true

# switch的case缩进

IndentCaseLabels: true

# 针对OC的block的缩进宽度

ObjCBlockIndentWidth: 

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

ObjCSpaceAfterProperty: true

# 每行字符的长度

ColumnLimit: 

# 注释对齐

AlignTrailingComments: true

# 括号后加空格

SpaceAfterCStyleCast: true

# 不在小括号里加空格

SpacesInParentheses: false

# 不在中括号里加空格

SpacesInSquareBrackets: false
  • 将这个文件加到 .xcodeproj 包内容里,就OK了,或者是放到主目录也是OK的

附:常用的设置命令

AccessModifierOffset: 0
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: false
BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 128
BreakBeforeBraces: Attach
CommentPragmas: ''
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 0
Cpp11BracedListStyle: false
DerivePointerBinding: false
IndentCaseLabels: true
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ObjCBlockIndentWidth: 4
PenaltyBreakBeforeFirstCallParameter: 100
PenaltyBreakComment: 100
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 100
PenaltyExcessCharacter: 1
PenaltyReturnTypeOnItsOwnLine: 20
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
TabWidth: 4
UseTab: Never

如此设置过一次就可以了,别的项目就不需要如此设置

Clang Format的更多相关文章

  1. clang format 官方文档自定义参数介绍(中英文)

    官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...

  2. 在Xcode中使用Clang Format

    Xcode中的Re-Indent,顾名思义,只是一个调整缩进的功能,完全依赖它来进行代码格式化显然不够用.我们使用了一个叫做ClangFormat-Xcode的插件,配合Re-Indent一起来做代码 ...

  3. clang format 自定义样式常用参数说明

    常用的格式设置: #如果为真(true),分析格式化过的文件中最常见的&和*的对齐方式.然后指针对齐仅作为回退 DerivePointerAlignment: false #缩进宽度 Inde ...

  4. a great tool for automatically formating your code!

    1. make your own format file at your project's root or file's folder. (The clang-format will automat ...

  5. 征服恐惧!用 Vim 写 iOS App

    我们都知道 Vim 和 Emacs 都是文本编辑器中的上古神器,你也许用 ctags,cscopes 配合 Vim 完成过大型 C 或者 C++ 的开发,你也许配合过其他插件,完成过 JavaScri ...

  6. ROS知识(21)----ROS C++代码格式化

    这里提供两种方法. 第一种方法:clang_format 1.安装clang format sudo apt-get install -y clang-format-3.6 2.从github的ros ...

  7. Android Studio xcode单步调试 WebRTC Android & iOS

    mac环境 如何在 Android Studio 里单步调试 WebRTC Android 的 native 代码. WebRTC 代码下载 depot tools 是 chromium 代码库管理工 ...

  8. Qt Creater中Clang-format的使用

    起因在于习惯性的想格式化代码,发现Qt Creater默认居然是没有代码格式化的,只有一个缩进,搞毛线啊!!! 搜索了下,倒是很容易就搜到了,Qt Creater中有个插件:beautifier,在 ...

  9. Vim 写 iOS App

    Vim 写 iOS App 我们都知道 Vim 和 Emacs 都是文本编辑器中的上古神器,你也许用 ctags,cscopes 配合 Vim 完成过大型 C 或者 C++ 的开发,你也许配合过其他插 ...

随机推荐

  1. Go语言 字符串处理

    LastIndex - 查询字符串最后出现的位置 原型:func strings.LastIndex(s string, sep string) int

  2. P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解价格

    NXP恩智浦P87LPC760/61/62/64/67/68/69/78/79芯片解密单片机破解 NXP LPC700系列单片机解密型号: P87LPC759.P87LPC760.P87LPC761. ...

  3. trigger() --工作中问题nav样式

    自动执行某元素的某个事件 $("#div").trigger("click");  //让系统自动执行单击事件 适用于nav样式中,下面横线绝对定位于nav.o ...

  4. python 小程序大文件的拆分合并

    1. 将大文件拆分为小文件 I 通过二进制的方式将大文件读取出来,将其拆分存,以不同的文件方式存放在一个目录下面 II 提供两种操作方式交互式和命令行模式 #! usr/bin/python # -* ...

  5. JavaScript(二) DOM

    当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model)通过 HTML DOM,可访问 JavaScript HTML 文档的所有元素. 通过 id 查找 HTML ...

  6. 丢手帕问题即约瑟夫问题的PHP解法

    问题描述:n个人排成一圈.从某个人开始,依次报数,数到m的人被杀死.下一个人重新从1开始报数,数到m的人被杀死.直到剩下最后一个人. 解决思路:从数学角度去看,每一次报数决定谁去死是一个n.m的求余数 ...

  7. Android MVP 利用rxjava 避免向Model传入监听方法

    传统的MVP: 1.抽离出View的接口,即ILoginView. 2.抽离Model的接口,即ILoginModel. 3.抽离Presenter的接口,即ILoginPresenter. 4.实现 ...

  8. linux kernel elv_queue_empty野指针访问内核故障定位与解决

    1. 故障描述 故障操作步骤: 单板上插了一个U盘,出问题前正在通过FTP往单板上拷贝文件,拷贝的过程中单板自动重启. 故障现象: Entering kdb (current=0xc000000594 ...

  9. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  10. linux 用户管理

    linux 用户管理 创建一个用户 foo 这个用户只能在/home/foo 上面增加删除文件, foo 不能在其他目录加减文件 useradd -d /home/foo -m foo [root@] ...