Xcode 4 : Pragma Mark Shortcut

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

12 Comments

  1. 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.

      • Doesn’t seem to be working in xcode 4, even with :

        • 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.

  2. Thanks! You can also put one at the end. I tend to like this style:

    #pragma mark – === View Lifecycle === –

  3. 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.

  4. You can also use a comment like

    // Mark: Initialization

    instead of a pragma directive

  5. 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.

Comments are closed.