Search code examples
iphoneobjective-cxcodexcode4pragma

Alternatives to #pragma that work inside methods in Xcode 4


As mentioned elsewhere, #pragmas inside methods don't work in Xcode 4.

What's a good way to do quick navigation to different sections within a long method, for example to specific cases of a switch statement?

(I try to keep methods clean & short where practical, but that's a topic for elsewhere.)


Solution

  • Not sure if this is exactly what you are looking for... What I like to do is to simply use code blocks like so:

    // some code
    
    {
         // some code that should stay together
    } // [a comment that explains what the code does]
    

    This at least allows you to use Xcode's code folding: When you fold in the block between the two { }, you get {...} // [your explanatory comment]

    It is also great to limit the scope of variables and can (very) slightly improve memory efficiency.