Search code examples
iosobjective-cxcodeoptimizationpragma

Can we create subdivisions of #pragma mark in Objective C?


We are using #pragma to make code more readable, accurate and separated into groups.

For example: I'm using #pragma like below:

//---------------------------------------------------------------

#pragma mark
#pragma mark Prefrences methods

//---------------------------------------------------------------

However there is something I was wondering, can we create sub section of #pragma in which we can divide it in one more layer.

Like I have lots of related methods like below:

enter image description here

You can see that these are preference related methods and can not be divide into other #pragma.

Just want to know whether there are any constants in Xcode like #subpragma or something like that which can divide #pragma?


Solution

  • Possibility:

    Category:

    #pragma mark 
    #pragma mark Level 1
    

    The two lines (two #pragma mark) will create a "separator".

    SubCategory:

    #pragma mark — Sublevel
    

    The single line (one #pragma mark) will just give a title. I used a to change the "indent" of the text.

    Sample:

    Render:
    enter image description here
    Code:

    #pragma mark
    #pragma mark Life Cycle
    -(id)init
    {
        self = [super init];
        if (self)
        {
    
        }
        return self;
    }
    
    #pragma mark
    #pragma mark Category 1
    
    -(void)methodCategory1{}
    
    #pragma mark — SubCat1
    -(void)method1Cat1SubCat1{}
    -(void)method2Cat1SubCat1{}
    
    #pragma mark — SubCat2
    -(void)method1Cat1SubCat2{}
    -(void)method2Cat1SubCat2{}
    
    
    
    #pragma mark
    #pragma mark Category 2
    
    -(void)methodCategory2{}
    
    #pragma mark — SubCat1
    -(void)method1Cat2SubCat1{}
    -(void)method2Cat2SubCat1{}
    
    #pragma mark — SubCat2
    -(void)method1Cat2SubCat2{}
    -(void)method2Cat2SubCat2{}