If you’re like me, you like your brace backets on their own lines, like this:
if (condition)
{
statements
}
If you’re even more like me, you make heavy use of Xcode’s autocomplete and snippets, like the following:
And finally, if you’re just like me, you get really disappointed when this happens:
if (condition) {
statements
}
What the hell, Xcode? Even the project templates have brace brackets on their own lines. What gives?
Thanks to some research, I found the file you need to edit. The problem is, Xcode is now distributed through the Mac App Store, so the steps are a little different. Here’s what you do.
cd /Applications/Xcode.app/Contents/PlugIns/IDECodeSnippetLibrary.ideplugin/Contents/Resources
and hit Enter.SystemCodeSnippets.codesnippets
, but let’s make a backup first. Type sudo cp SystemCodeSnippets.codesnippets SystemCodeSnippets.codesnippets.backup
and hit Enter.sudo vim SystemCodeSnippets.codesnippets
sudo open -a TextMate SystemCodeSnippets.codesnippets
Do a “Find” for the word “condition” and you should find almost all the instance of the snippets you want to modify. It’ll look like this:
<key>IDECodeSnippetVersion</key>
<integer>1</integer>
<key>IDECodeSnippetCompletionPrefix</key>
<string>if</string>
<key>IDECodeSnippetContents</key>
<string>if (<#condition#>) {
<#statements#>
}</string>
Just put a new line before the opening brace bracket.
<key>IDECodeSnippetVersion</key>
<integer>1</integer>
<key>IDECodeSnippetCompletionPrefix</key>
<string>if</string>
<key>IDECodeSnippetContents</key>
<string>if (<#condition#>)
{
<#statements#>
}</string>
This will find all the if statements and most loops; search for the text “forin” to modify the fast enumeration snippet.
Save the file and restart Xcode. That’s it!
Update : My friend Zev is maintaining an up-to-date version of SystemCodeSnippets.codesnippets
for the latest Xcode version on GitHub. Go check it out.