Pages

Monday 2 February 2015

#warning pragma in XCode

#pragma's are one of the interesting part of the XCode, which helps to organise your code.
When your .m file contains thousands of line and hundreds of methods, the file becomes clumsy.

You can avoid this by structuring the code by grouping methods with pragma marks. When you give pragma directive over a method, all the methods under this pragma are grouped together in the document items. You can see that in the following screenshot.




But the fun part doesn't end here.

Have you ever hard-coded something in your code for testing something, and you forget that completely. Well, that happens a lot. What if something reminds you to fix this when you finish your work?

XCode have a pragma directive particularly for this. It is the #warning pragma. Whenever you give a warning pragma anywhere in your code, the XCode compiler gives a real warning (yellow triangle that appears near the line number). You can see the compiler warning in the line navigator, Issue navigator like the other XCode warnings.

But this doesn't stop your code from executing, you can use the #error pragma if you want to stop the code from execution.


You can also make use of some comments that start with the following keywords.
// FIXME:, // ???,  // !!!, // MARK

The comment you enter after these will appear in the document items (Option + 6).

No comments:

Post a Comment