Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode: Adjusting indentation of auto-generated braces?

Code auto-generated by Xcode seems to have the opening brace on the same line by default:

@interface Controller : NSObject {

}

I'd like the opening brace on a line of its own, like this:

@interface Controller : NSObject 
{

}

This applies in general to any method / class auto-generated by Xcode. In Xcode preferences I have "Indent solo { by" set to 0: alt text

How can I fix this?

like image 693
Debajit Avatar asked Dec 25 '08 11:12

Debajit


3 Answers

For Xcode 3.x, you can use the following: If you open up a terminal session and enter
defaults write com.apple.Xcode XCCodeSenseFormattingOptions '{ "BlockSeparator" = "\n" ; }'
it will start new blocks of code on a new line. Note that you will have to restart XCode if you have it opened in order for the new defaults to be read and used.

For Xcode 4.x to 6.x (current) I suggest you use Snippet Edit as a handy tool for editing the snippets that define the Xcode autocompletion. At the current time it's free and works great.

like image 126
Laughing_Jack Avatar answered Oct 09 '22 01:10

Laughing_Jack


The New Project and New File commands don't really generate any code; they fill in templates.

You'll need to create your own templates (probably based on Apple's) with the changes you want.

In Xcode 3.1, the stock templates are in /Developer/Library/Xcode. You'll put your modified copies in ~/Library/Application Support/Developer/Shared/Xcode. Pay attention to the subfolders of those folders.

like image 45
Peter Hosey Avatar answered Oct 09 '22 02:10

Peter Hosey


This is something I would like to see too, I don't like the "new school" way of curly braces on the same line as functions or loop control.

When editing and shuffling lines of code around, it's easier to keep everything relevant in one line. Curly braces should only define scope, they're not part of the function definition or program execution (like in if, for etc..).

Modifying all the templates is not really a good solution, but thanks for the info anyway.

like image 35
Sakari Avatar answered Oct 09 '22 02:10

Sakari