我正在搜索一个插件,可以在XCode中自动设置objective-c代码的格式,如果有一组可选的样式设置格式也会非常有用,

I'm aiming to follow Google's code convention: http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml as a start, any help is appreciated.

推荐答案

updated April 2013

正如罗杰·诺兰(Roger Nolan)和rcw3(rcw3)所建议的,你可以用Uncrustify更进一步.最新发布版本可下载here.


集成到Xcode中

与Xcode的集成取决于安装的Xcode版本.

  • Xcode 4.6 & newer

贝诺·波登BBUncrustifyPlugin-Xcode

该插件提供了从Xcode的"编辑"菜单("取消选定文件的 rust 蚀"、"取消激活文件的 rust 蚀"和"取消选定行的 rust 蚀")访问"取消 rust 蚀"的权限.只需构建项目,就可以编译并安装插件.

截至2013年4月2日,该插件包含Uncrustify 0.60和Uncrustify配置文件.要使用自定义解锁配置文件,请确保阅读标题为"如何自定义解锁配置"的部分README.md个.

Note: To use Uncrustify from the command line, for example as part of a git hook, I recommend building and installing 100 independently. For consistency sake, I also recommend replacing the version of Uncrustify that comes with the plugin with a link to the version Uncrustify that was independently built and installed. The following is how to do that:

cd ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/UncrustifyPlugin.xcplugin/Contents/Resources
mv uncrustify uncrustify.orig
ln -s /usr/local/bin/uncrustify uncrustify
  • Xcode 4.x

乔纳·威廉姆斯Code Formatting in Xcode 4

  • Xcode 3.x

乔纳·威廉姆斯Code Formatting in Xcode


取消信任配置文件示例

我用于Objective-C的Uncrustify 0.60配置文件位于here.


更新Uncrustify配置文件以获取新版本的Uncrustify

要为新版本的Uncrustify更新Uncrustify配置文件,请启动终端并键入:

mv uncrustify.cfg uncrustify.cfg.old
uncrustify -c uncrustify.cfg.old --update-config > uncrustify.cfg

要查看对"解锁"配置所做的更改,请在终端类型中:

diff uncrustify.cfg.old uncrustify.cfg

查看未授权配置文件的文档版本

要查看文件化版本的解锁配置文件,请启动终端并键入:

uncrustify -c uncrustify.cfg --show-config

Objective-c相关问答推荐

在 Objective-C 中完成受保护属性的解决方法

UITableView 无限滚动

重复符号 _OBJC_METACLASS_$_ClassName

何时使用静态字符串与 #define

如何将 NSDictionary 转换为 NSMutableDictionary?

避免NSArray 在被枚举时发生Mutations

UITextView 禁用文本 Select

如何判断字符串是否仅包含目标C中的字母数字字符?

iOS:使用设备修饰符加载 xib 文件?

Objective-C 中是否有一些文字字典或数组语法?

如何编写 OS X Finder 插件

iOS 8 Mapkit Objc 无法获取用户位置

如何在 Objective-C (iOS) 中判断 NaN 值

如何在 Objective-C 中将 NSString 解析为 BOOL?

两个 NSDate 对象之间的区别 - 结果也是一个 NSDate

单例释放方法产生警告?

获取临时目录中文件的文件路径和 URL

Instruments Allocations 跟踪用户定义类的对象的分配和解除分配

更改 UITextField 占位符字体

无法加载从设备上运行的包中的 nib 引用的图像