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. scrapy爬虫结果插入mysql数据库

    1.通过工具创建数据库scrapy

  2. mybatis自增长插入id

    第一种: <insert id="insertUser" parameterClass="ibatis.User"> <selectKey r ...

  3. 在Sublime TEXT3中添加brogrammer-theme主题配色方案

    喜欢用sublime text3的都知道原配的主题要么就是背景颜色太亮太累眼,要么就是配色太少不便于一眼看出哪有问题.所以在此推荐一个brogrammer-theme的主题,配色非常的全而且添加了扁平 ...

  4. html5与css3

    Video属性 符号:<video>这里插入视频</video> Drag 和 drop属性 为了使元素可拖动,把 draggable 属性设置为 true: 2.       ...

  5. 【BZOJ3943】[Usaco2015 Feb]SuperBull 最小生成树

    [BZOJ3943][Usaco2015 Feb]SuperBull Description Bessie and her friends are playing hoofball in the an ...

  6. bzoj3572又TM是网络流

    = =我承认我写网络流写疯了 = =我承认前面几篇博文都是扯淡,我写的是垃圾dinic(根本不叫dinic) = =我承认这道题我调了半天 = =我承认我这道题一开始是T的,后来换上真正的dinic才 ...

  7. swift-func(函数)

    函数是一个组织在一起语句集合,以执行特定任务. Swift 函数类似于简单 C 函数以及复杂的 Objective C 语言函数. 它使我们能够通过函数调用内部的局部和全局参数值. 像其他任何语言一样 ...

  8. BZOJ2908: 又是nand

    Description 首先知道A nand B=not(A and B) (运算操作限制了数位位数为K)比如2 nand 3,K=3,则2 nand 3=not (2 and 3)=not 2=5. ...

  9. PHP:( && )逻辑与运算符使用说明

    第一次看到以下语句的写法大惑不解 ($mCfg['LockChinaIp']==1 && (int)$_SESSION['AdminUserId']==0 && sub ...

  10. niginx 负载均衡

    下面是Nginx安装 直接yum install nginx不行,要先处理下源,下面是安装完整流程,十分简单: 1.CentOS 6,先执行:rpm -ivh http://nginx.org/pac ...