What is a #pragma mark?

Featured Image

One of many features in Xcode that developers forgot to use is #pragma mark directives. What is a #pragma mark? #pragma marks are simple directives that help us better organize our implementation code.

When you are using #pragma mark directives in implementation code, you are in one way adding titles for one or more segments of your code in Functions Menu. This is very useful feature, because in the end, your code (your list of your method definitions) looks neater and more organized. For example, if you put #pragma mark Private methods in your implementation code right above -(void) initUI{ } method, then the Functions Menu (in the navigation bar) will show Private methods for that definition and for any other definition you define or group together with -(void) initUI{ } method.

If you have problem with #pragma mark appearance (sections are not in array as you define), ensure that Sort List Alphabetically is not checked in the Code Sense preference settings. While this feature may be less necessary in smaller applications, when you have application with classes with more the ten method definitions, it’s a very good idea to use #pragma mark directives.

5
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Ivan Kalaica

Senior OSX and iOS SDK Developer

At Inchoo, Ivan Kalaica is a Senior OSX and iOS SDK developer.

Other posts from this author

Discussion 5 Comments

Add Comment
  1. One thing to note, if in your general preferences for XCode you checked to ’sort alphabetically’ it will screw up all your pragma notation in the pull down. I struggled trying to figure out why none of my pragma looked like yours … and that was the reason.

  2. anonymous

    If you do:

    #pragma mark -

    You can draw a line in your functions list to further organize your sections of code!

  3. Steven

    You really did not answer the question posed by your headline. Back to Google for me…

  4. John

    ^Yes, he did answer it actually. Thanks!

  5. Trung Tin Mai

    Hi Ivan,

    I wait to adjust the micro volume of iOS device, but I don’t found any way yet.

    Can you give me your advice, the solution to fix that problem.

    Thank you,
    Tin

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top