Question

I would like to know that if we #define a particular function like this

#define POST_NOTIFICATION(NAME, OBJECT) [[NSNotificationCenter defaultCenter] postNotificationName:NAME object:OBJECT]

will using above decrease performance?

Was it helpful?

Solution

No. #define is a preprocessor directive meaning that anywhere the preprocessor sees the POST_NOTIFICATION symbol, it will replace it with the [[NSNotificationCenter ...]] code.

OTHER TIPS

No, it won't decrease performance. The #define directives are preprocessor directives, which are "replaced" in code before compiling, so the final binary code is the same. However you should refrain from using defines ... It might seem to make the code more readable, however it does not really do it ... Also for one-lines like in the example you gave the benefit probably is not that high to use it.

However to answer your question, the final binary is not different if you use this construct, so there is no performance decrease.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top