Code Organization Best Practices

I’ve been working on a pretty large OS X development project for the past few weeks. With any large project, some source code files can become pretty insane with the amount of methods and code in general. I try to adhere to a set of best practices for organizing my code.

I’ve outlined my organization method below, which I am sure is different from yours. I’m curious as to how you organize your code.


@implementation ClassName

#pragma mark -
#pragma mark Static Methods

// +initialize

#pragma mark -
#pragma mark Init Methods & Superclass Overrides

// dealloc, awakeFromNib, etc

#pragma mark -
#pragma mark Subclass Methods

#pragma mark -
#pragma mark IBActions

#pragma mark -
#pragma mark NSApplication Delegate Methods

// applicationWillTerminate, etc.

#pragma mark -
#pragma mark Delegate Methods

// One pragma section per class I am working with.

#pragma mark -
#pragma mark Accessors & Mutators

@end

Tip for those that don’t know: #pragma mark - will add a divider line in your source code when you try to view it.

pragma-dash.png