In a tip nearly a year ago, Xcode and #pragma mark, I described how to insert pragma mark directives to organize your code.
#pragma mark - #pragma mark Initialization |
Here is how things may look with multiple pragma directives:
With Xcode 4, you can now combine both pragma statements into one line:
#pragma mark - Initialization |
Unfortunately TODO and FIXME have been killed.
They haven’t. The format just has to be exact:
// FIXME: Fix This
// TODO: Do This
If there is no : or no content after it it won’t show.
Thanks, I never used a colon.
Doesn’t seem to be working in xcode 4, even with :
What version of 4 are you using?
Xcode version 4.0.2 on snow leapord
Ah right, I’ve only tested it as working on 4.1.1 and 4.2 beta.
It works for me but not inside a method body. Seems like a bug. This is in Xcode 4.2.
Thanks! You can also put one at the end. I tend to like this style:
#pragma mark – === View Lifecycle === –
Is there a way to do code folding with pragmas? There’s something like this in Visual Studio (or, at least, there used to be; it’s been a few years). You can tag the beginning and ending of a code block and VS will allow you to fold that entire block. That’s one of the features I’ve missed in Xcode.
You can also use a comment like
// Mark: Initialization
instead of a pragma directive
Nice. I’ve not been using #pragma very much, but being able to jump to different sections in the code with the dropdown clearly has advantages.