问题描述
似乎新的 Xcode 4 不再应用 XCCodeSenseFormattingOptions
.至少对我来说:(
It seems like the new Xcode 4 does not apply the XCCodeSenseFormattingOptions
anymore. At least for me :(
无论如何,您知道如何在 Xcode 4 中将左大括号放到新行以进行自动补全吗?我曾经在终端中输入这个,但它不适用于新的 Xcode.
Anyway, do you know how to put the opening brace to the new line for autocompletion in Xcode 4? I used to type this in terminal but it does not work for the new Xcode.
defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\\n" PreMethodDeclSpacing ""
推荐答案
XCode 4 使用代码片段"进行自动补全,并附带了一个内置库:您可以通过单击代码片段库来查看代码片段库库窗格中的 { }
图标,它可能位于您的 XCode 主窗口的右下方.
XCode 4 uses "code snippets" to do autocompletion, and ships with a built-in library of them: You can view the Code Snippet Library by clicking on the { }
icon in the Library Pane, which is probably on the lower right-hand side of your main XCode window.
XCode 4 的所有内置代码片段都将左大括号与语句放在同一行——这是 XCode 4 的 if
语句的代码片段,例如:
All of XCode 4's built-in code snippets put the opening brace on the same line as the statement – this is XCode 4's code snippet for an if
statement, for example:
if (<#condition#>) {
<#statements#>
}
因此,如果您希望 XCode 4 像这样自动完成:
So if you wanted XCode 4 to autocomplete like so:
if (<#condition#>)
{
<#statements#>
}
...然后您必须相应地编辑代码片段.这反过来又会导致两个问题:
...then you'd have to edit the code snippet accordingly. This, in turn, leads to two problems:
- XCode 4 中内置了 44 个代码片段,您必须分别编辑每一个.
- XCode 4 不允许您编辑内置代码片段.
这些问题比在 XCode 3 中工作的简单 defaults write
命令更具挑战性 - 但它可能,如果您有决心并且可以编辑属性列表, 深入了解 XCode 4 的内幕并一一更改这些代码片段.
These problems are more challenging than the simple defaults write
command that worked in XCode 3 – but it is possible, if you're determined and you can edit property lists, to delve into the guts of XCode 4 and change these code snippets one by one.
/Developer/Library/Xcode/PrivatePlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
包含 XCode 4 的内置代码片段库.这可能不言而喻,但是您应该在收费和进行编辑之前备份此文件 - 之后您应该制作另一个备份,并保留一份包含新的和改进的代码片段的文件副本,因为您将当您安装下一版本的 XCode 4 时,几乎肯定会覆盖 /Developer/Library/Xcode
的内容.(Apple 也可能会更改此文件的格式,添加新的代码片段,或者可能使此答案无效的任何其他事情.)
/Developer/Library/Xcode/PrivatePlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
contains XCode 4's library of built-in code snippets. This probably goes without saying, but you should make a backup of this file before charging in and making edits – and afterwards you should make another backup, and set aside a copy of the file with your new and improved code snippets, because you'll almost certainly overwrite the contents of /Developer/Library/Xcode
when you install the next release of XCode 4. (It's also possible that Apple will change the format of this file, add new code snippets, or do any number of other things that could render this answer ineffective.)
如果您直接从 App Store 安装了 Xcode 4.3 或更高版本,则所有内容都在 Xcode.app 包中.SystemCodeSnippets.codesnippets 的路径是 /Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
.
If you have Xcode 4.3 or later installed directly from the App Store, everything is inside the Xcode.app bundle. The path to SystemCodeSnippets.codesnippets is /Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
.
无论如何,你会发现上面的文件包含几个这样的条目:
Anyhow, you'll find the above file contains several entries like this one:
<dict>
<key>IDECodeSnippetVersion</key>
<integer>1</integer>
<key>IDECodeSnippetCompletionPrefix</key>
<string>if</string>
<key>IDECodeSnippetContents</key>
<string>if (<#condition#>) {
<#statements#>
}</string>
<key>IDECodeSnippetIdentifier</key>
<string>D70E6D11-0297-4BAB-88AA-86D5D5CBBC5D</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.C</string>
<key>IDECodeSnippetSummary</key>
<string>Used for executing code only when a certain condition is true.</string>
<key>IDECodeSnippetTitle</key>
<string>If Statement</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>CodeBlock</string>
</array>
</dict>
这是自动完成 if
语句的代码片段.编辑 IDECodeSnippetContents
将左大括号放在新行,保存您的工作,然后重新启动 XCode 4;如果一切顺利,您应该能够输入 if
语句并查看结果.
This is the code snippet for autocompleting an if
statement. Edit the IDECodeSnippetContents
to put the opening brace on a new line, save your work, and then restart XCode 4; if all goes well, you should be able to type an if
statement and see the results.
您至少需要再进行六次编辑以涵盖最常见的自动完成(for
、while
等),如果您想要彻底,它将需要大约 40 次单独的编辑.这是很多工作,但是如果您真的真的希望 XCode 4 的自动完成功能将您的左大括号放在单独的行上,则可以完成.
You'll need to make at least half a dozen more edits to cover the most common autocompletes (for
, while
, etc.), and if you want to be thorough it'll take somewhere around 40 separate edits. It's a lot of work, but if you really, really want XCode 4's autocompletion to put your opening braces on a separate line, it can be done.
这篇关于Xcode 4 在新行上打开大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!