Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pragma directive in UIViewController

When i create a UITableViewController class, the template has some #pragma directives:

#pragma mark -
#pragma mark View lifecycle

at the start and:

#pragma mark -
#pragma mark Table view data source

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

like image 434
windson Avatar asked Dec 21 '10 03:12

windson


Video Answer


2 Answers

You dont need to use them. They are simply for code "prettiness" and separating methods.

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

#pragma mark - draws the line and #pragma mark My Delegates shows you whatever text you see in BOLD.

alt text

like image 70
WrightsCS Avatar answered Sep 19 '22 23:09

WrightsCS


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

If you want to use pragma's on your own, just drop the first line and move the dash to the second line.

#pragma mark -
#pragma mark View Lifecycle

and

#pragma mark - View Lifecycle

produce exactly the same.

like image 36
Dominic Frei Avatar answered Sep 18 '22 23:09

Dominic Frei