Xcode 4 在新行上打开大括号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5120343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 4 with opening brace on new line
提问by panchapol
It seems like the new Xcode 4 does not apply the XCCodeSenseFormattingOptions
anymore. At least for me :(
似乎新的 Xcode 4 不再适用XCCodeSenseFormattingOptions
了。至少对于我来说 :(
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.
无论如何,您知道如何在 Xcode 4 中将左大括号放到新行以进行自动补全吗?我曾经在终端中输入这个,但它不适用于新的 Xcode。
defaults write com.apple.Xcode XCCodeSenseFormattingOptions -dict BlockSeparator "\n" PreMethodDeclSpacing ""
回答by Scott Forbes
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 窗口。
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:
XCode 4 的所有内置代码片段都将左大括号与语句放在同一行——这是 XCode 4 的if
语句代码片段,例如:
if (<#condition#>) {
<#statements#>
}
So if you wanted XCode 4 to autocomplete like so:
因此,如果您希望 XCode 4 像这样自动完成:
if (<#condition#>)
{
<#statements#>
}
...then you'd have to edit the code snippet accordingly. This, in turn, leads to two problems:
...然后您必须相应地编辑代码片段。这反过来又会导致两个问题:
- There are 44 code snippets built into XCode 4, and you'd have to edit each one separately.
- XCode 4 won't allow you to edit the built-in code snippets.
- XCode 4 中内置了 44 个代码片段,您必须分别编辑每一个。
- 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.
这些问题不是简单的更具挑战性defaults write
的命令,在3 XCode的工作-但它是可能的,如果你确定,你可以编辑属性列表,钻研的XCode 4的胆量和修改这些代码段一个接一个。
/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.)
/Developer/Library/Xcode/PrivatePlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
包含 XCode 4 的内置代码片段库。这可能不言而喻,但是您应该在收费和进行编辑之前备份此文件 - 之后您应该制作另一个备份,并保留一份包含新的和改进的代码片段的文件副本,因为您将几乎肯定会/Developer/Library/Xcode
在您安装下一版本的 XCode 4 时覆盖内容。(Apple 也可能会更改此文件的格式、添加新的代码片段或执行任何其他可能使此答案无效的事情。)
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
.
如果您直接从 App Store 安装了 Xcode 4.3 或更高版本,则所有内容都在 Xcode.app 包中。SystemCodeSnippets.codesnippets 的路径是/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.
这是自动完成if
语句的代码片段。编辑将IDECodeSnippetContents
左大括号放在新行上,保存您的工作,然后重新启动 XCode 4;如果一切顺利,您应该能够输入if
语句并查看结果。
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, reallywant XCode 4's autocompletion to put your opening braces on a separate line, it can be done.
你需要做至少有半打以上的编辑覆盖最常见的自动完成(for
,while
,等),如果你想成为彻底的,它会采取某处大约40个独立的编辑。这是很多工作,但是如果您真的,真的希望 XCode 4 的自动完成功能将您的左大括号放在单独的行上,则可以完成。
回答by Ben Stiglitz
There's no way to do it in Xcode 4. Please do file a bug.
在 Xcode 4 中没有办法做到这一点。请提交一个错误。
回答by zeiteisen
Just make a user code snipped which overrides Apple's version. Do this by entering in the Completion Shortcut field the same name as in the default snipped. Look at this video for a howto: http://s3.amazonaws.com/screencasts.pragmaticstudio.com/017_custom_code_snippets.mov
只需剪下一个覆盖 Apple 版本的用户代码即可。为此,请在“完成快捷方式”字段中输入与默认截取的名称相同的名称。观看此视频了解操作方法:http: //s3.amazonaws.com/screencasts.pragmaticstudio.com/017_custom_code_snippets.mov
回答by Sveinung Kval Bakken
Check out my modified (system wide) snippets for Xcode 4.2 here:
在此处查看我为 Xcode 4.2 修改的(系统范围的)片段:
http://forrst.com/posts/Put_that_where_it_belongs_Xcode-PNL
http://forrst.com/posts/Put_that_where_it_belongs_Xcode-PNL
It should take care of all the relevant opening curly braces for iOS development..
它应该处理所有与 iOS 开发相关的大括号。
回答by Leslie
In Xcode 4.3.1, if you edit the following file as sudo from the terminal, as Scott Forbes described above, you can change where the opening brace appears. It would go away with new installations of Xcode, I would imagine, so I would vote that this is a bug with Apple too.
在 Xcode 4.3.1 中,如果您从终端将以下文件编辑为 sudo,如上文 Scott Forbes 所述,您可以更改左大括号出现的位置。我想它会随着 Xcode 的新安装而消失,所以我会投票认为这也是 Apple 的一个错误。
/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
/Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources/SystemCodeSnippets.codesnippets
Leslie
莱斯利
回答by tnq177
I used SnippetEdit for Xcode4 and it works amazingly. It basically lets you replace old snippets given by xcode with the new ones defined by yourself. See more here: https://www.macupdate.com/app/mac/43352/snippet-edit
我为 Xcode4 使用了 SnippetEdit,它的效果非常好。它基本上可以让您用自己定义的新片段替换 xcode 给出的旧片段。在此处查看更多信息:https: //www.macupdate.com/app/mac/43352/snippet-edit