似乎新的 Xcode 4 不再适用XCCodeSenseFormattingOptions
了。至少对我来说 :(
无论如何,你知道如何在 Xcode 4 中将左大括号放到新行以自动完成吗?我曾经在终端中输入这个,但它不适用于新的 Xcode。
defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\\n" PreMethodDeclSpacing ""
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.
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#>
}
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:
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
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.)
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>
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.
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 中没有办法做到这一点。请提交一个错误。
在此处查看我为 Xcode 4.2 修改的(系统范围的)片段:
http://forrst.com/posts/Put_that_where_it_belongs_Xcode-PNL
它应该为 iOS 开发处理所有相关的左花括号。
只需剪掉一个覆盖苹果版本的用户代码。通过在“完成快捷方式”字段中输入与默认截图中相同的名称来执行此操作。查看此视频以了解操作方法:http: //s3.amazonaws.com/screencasts.pragmaticstudio.com/017_custom_code_snippets.mov
我为 Xcode4 使用了 SnippetEdit,它的效果非常好。它基本上可以让你用你自己定义的新片段替换 xcode 给出的旧片段。在此处查看更多信息:https ://www.macupdate.com/app/mac/43352/snippet-edit
在 Xcode 4.3.1 中,如果您从终端以 sudo 的形式编辑以下文件,如上述 Scott Forbes 所述,您可以更改左大括号出现的位置。我想它会随着 Xcode 的新安装而消失,所以我会投票认为这也是 Apple 的一个错误。
/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
莱斯利