Clicky

iOS Dev Nugget 12 Use #pragma to help organize your code

.

Need to run a code review on your codebase? Hire me

Other than suppressing compiler warnings with #pragma, it is very useful to organize codes by using #pragma marks as section headers and dividers.

For example, like this:

@implementation SomeClass

#pragma mark Accessors

//Code...

#pragma mark Overridden SomeParentClass

//Code...

The #pragma marks are displayed in bold in Xcode when you browse the list of methods, letting you group code for specific purposes together. You can also use the following to draw a line in the list of methods.

#pragma mark -


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues