Xcode:调整自动生成的大括号的缩进?
默认情况下,Xcode 自动生成的代码似乎在同一行上有左大括号:
@interface Controller : NSObject {
}
我希望左大括号在自己的一行上,如下所示:
@interface Controller : NSObject
{
}
这通常适用于 Xcode 自动生成的任何方法/类。 在 Xcode 首选项中,我将“Indent alone { by”设置为 0:
我怎样才能解决这个问题?
Code auto-generated by Xcode seems to have the opening brace on the same line by default:
@interface Controller : NSObject {
}
I'd like the opening brace on a line of its own, like this:
@interface Controller : NSObject
{
}
This applies in general to any method / class auto-generated by Xcode. In Xcode preferences I have "Indent solo { by" set to 0:
How can I fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
对于 Xcode 3.x,您可以使用以下命令:
如果您打开终端会话并输入
默认写入 com.apple.Xcode XCCodeSenseFormattingOptions '{ "BlockSeparator" = "\n" ; }'
它将在新行上开始新的代码块。 请注意,如果您打开了 XCode,则必须重新启动 XCode 才能读取和使用新的默认值。
对于 Xcode 4.x 到 6.x(当前),我建议您使用 Snippet Edit 作为方便的编辑工具定义 Xcode 自动完成的代码片段。 目前它是免费的并且运行良好。
For Xcode 3.x, you can use the following:
If you open up a terminal session and enter
defaults write com.apple.Xcode XCCodeSenseFormattingOptions '{ "BlockSeparator" = "\n" ; }'
it will start new blocks of code on a new line. Note that you will have to restart XCode if you have it opened in order for the new defaults to be read and used.
For Xcode 4.x to 6.x (current) I suggest you use Snippet Edit as a handy tool for editing the snippets that define the Xcode autocompletion. At the current time it's free and works great.
新建项目和新建文件命令并不真正生成任何代码; 他们填写模板。
您需要创建自己的模板(可能基于 Apple 的模板)并进行所需的更改。
在 Xcode 3.1 中,库存模板位于
/Developer/Library/Xcode
中。 您将把修改后的副本放在~/Library/Application
Support/Developer/Shared/Xcode
中。 请注意这些文件夹的子文件夹。The New Project and New File commands don't really generate any code; they fill in templates.
You'll need to create your own templates (probably based on Apple's) with the changes you want.
In Xcode 3.1, the stock templates are in
/Developer/Library/Xcode
. You'll put your modified copies in~/Library/Application
Support/Developer/Shared/Xcode
. Pay attention to the subfolders of those folders.这也是我想看到的,我不喜欢花括号与函数或循环控制在同一行的“新派”方式。
当编辑和打乱代码行时,可以更轻松地将所有相关内容保留在一行中。 大括号应该只定义作用域,它们不是函数定义或程序执行的一部分(例如 if、for 等)。
修改所有模板并不是一个好的解决方案,但无论如何还是感谢您提供的信息。
This is something I would like to see too, I don't like the "new school" way of curly braces on the same line as functions or loop control.
When editing and shuffling lines of code around, it's easier to keep everything relevant in one line. Curly braces should only define scope, they're not part of the function definition or program execution (like in if, for etc..).
Modifying all the templates is not really a good solution, but thanks for the info anyway.
阅读此内容: XCCodeSenseFormattingOptions
本文档描述了自动完成将用于大括号和参数样式的所有格式选项。 这是我的:
Read this: XCCodeSenseFormattingOptions
This document describes all the formatting options that auto-complete will use for brace and argument style. Here are mine:
如果您想在所有情况下都有自己喜欢的风格,则需要结合 Laughing_Jack 的答案和 Peter Hosey 的答案。 除了 Peter Hosey 所说的之外,您可能还想知道 Cocoa Touch 文件模板位于以下位置。 您也可以将该目录复制到自定义模板中:
Xcode 用户默认值在手动输入代码时为您提供样式,文件模板在自动生成新类等时提供样式。
If you want to have your preferred style in all situations, you need a combination of Laughing_Jack's answer and Peter Hosey's answer. In addition to what Peter Hosey said, you may also like to know that the Cocoa Touch file templates are in the following location. You can copy that directory to your custom templates too:
The Xcode User Defaults give you your style when typing out code by hand, the file templates provide it when auto-generating a new class etc.
我相信“defaults write com.apple.Xcode”在最新版本的 Xcode (7.x) 上不起作用。
解决方法是编辑默认的代码片段。
但是,Xcode 不允许修改默认的代码片段。
为了修改它们,您可以从此处下载“Snippet Edit”程序
I believe that "defaults write com.apple.Xcode" doesn't work on the latest versions of Xcode (7.x)
The workaround is to edit the default Code Snippets.
However, Xcode doesn't allow to modify the default Code Snippets.
In order to modify them, you can download a "Snippet Edit" program from here