Pragma directive in UIViewController

When I create the UITableViewController class, there are some #pragma directives in the template:

#pragma mark - #pragma mark View lifecycle 

at the beginning and:

 #pragma mark - #pragma mark Table view data source 

at the beginning of the implementation of data source methods.
I know that #pragma is a compiler directive, but why do we need to notify the compiler above?
Does this mean that we should give the #pragma every time we implement any data source / delegate protocols?

+7
source share
2 answers

You do not need to use them. They are just for prettiness code and separation methods.

In my screenshot example, they are used to draw the lines that you see when separating delegates.

#pragma mark - draws a line, and #pragma mark My Delegates shows any text that you see in BOLD .

alt text

+13
source

In addition to the absolutely correct WrightsCS answer, I want to point out something else:

If you want to use the pragma yourself, just omit the first line and move the dash to the second line.

 #pragma mark - #pragma mark View Lifecycle 

and

#pragma mark - View Lifecycle

create exactly the same thing.

+1
source

All Articles