tags:

views:

14

answers:

1

In XCode, autocompletion has the first bracket appear on the same line:

    if (<#condition#>) {
        <#statements#>
    }

Is there a way to have it appear like so, so that I dont have to change it every time?

    if (<#condition#>)
    {
        <#statements#>
    }
+3  A: 

You can modify this by editing the Xcode Macros file.

  • Copy the Xcode C Macro file to your User's Xcode macro directory:

    mkdir -p ~/Library/Application Support/Developer/Shared/Xcode/Specifications && \ cp /Developer/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/C.xctxtmacro ~/Library/Application\ Support/Developer/Shared/Xcode/Specifications

  • I find xml easier to read and normally convert the macro file to xml1

    plutil -convert xml1 C.xctcmacro

  • Edit the macro file for your new styles

    cd $SpecificationsDir/ && vim C.xctxtmacro

  • You'll find the relevant section around line #46 as part of the c.block identifier. If you add a breakline after the $(BlockSeparator){ portion it'll then expand to that.

At this point you may notice that interesting looking key called "BlockSeparator". If you wish this style to apply to all blocks in all languages (while, for, switch, etc) there is an easier route:

defaults write com.apple.Xcode XCCodeSenseFormattingOptions '{ "BlockSeparator" = "\n" ; }'

You can learn more about xcode macros (mostly) by reading the already existing ones. There's a (painfully brief) review of them in the Xcode Editor section of the documentation.

jkyle