Monday, August 27, 2012

The Use of #Pragma

This lesson is completely useful.  It tells you what #pragma is really used for as 
opposed to just a cursory definition.  It's really great.

Check it out.

Nutshell:  #pragma in iOS can be used for a number of purposes.  Really it's just to 
speak directly to the compiler and give it specific instructions. 

It can be used to give a warning in the compiler, i.e.

#warning dude, do not forget to add error checking code here.

It can be used to add an error:

#error dude, stop.  You have got to put a div by zero exception here.

It can be used to tell the compiler not to alert you to something that you all ready know 
about, i.e.,

NSString *foo;
#pragma unused(foo)

return 5;

Above it supresses the unused foo string warning.

Also it can be used to suppress other more intricate warnings.  

1
2
3
4
5
6
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
 
[myObj performSelector:mySelector withObject:name];
 
#pragma clang diagnostic pop

See this Praga Link Uses for that.  Nice.

No comments:

Post a Comment