Apple's Objective-C documentation, references, and generated code seem to be totally inconsistent with their coding style. I can not determine the "preferred" style (if one exists) for Objective-C and Cocoa source code.
Here's what I've ran into so far.
Tab settings
Xcode's default setting is set to tabs. However, generated projects are always created with 4 spaces regardless of your tab settings. Worse, some generated code has stray tabs hanging around. Downloaded code examples seem to vary from project to project as well.
Method definition spacing
In Apple's example code, different styles of method definition even vary within a single file. But the most common style of spacing seems to include a space between the -
or +
and spaces only between addition arguments. This style is also used in the Xcode reference library which leads me to believe it is the preferred style.
- (IBAction)reloadData:(id)sender;
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
Inconsistent variates:
- (IBAction) reloadData:(id)sender;
- (IBAction)reloadData:(id) sender;
-(IBAction)reloadData:(id)sender;
- (IBAction) reloadData: (id)sender;
- (id)tableView: (NSTableView *)aTableView objectValueForTableColumn: (NSTableColumn *)aTableColumn row: (NSInteger)rowIndex
Brace style
Another thing that is widely inconsistent is the brace style. There are two popular styles:
Open brace on its own line:
@interface Foo : NSObject
{
}
- (id)init
{
}
Open brace on the same line as the method declaration:
@interface Foo : NSObject {
}
- (id)init {
}
Question
Is there a recommended coding style for Objective-C by Apple? If not, what style do you prefer and why?