I have a piece of code I'm using fairly often and would like to make a macro out of it. I'm not exactly sure how to do that though. Here's the code I want to use
UIImage *titleImage = [UIImage imageNamed:@"myLogo.png"];
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
self.navigationItem.titleView = titleImageView;
[titleImageView release];
I want to define this block as a macro so I can later say for instance addImage(...); Thanks for your help.
Try the following macro
Use it like this:
The use of
{}
creates a scope block, which will prevent problems with variable redefinitions (if you have variables with the same name, where you use the macro).use #define with the preprocessor, write a function, or write a method for your class.
#define Image_Macro @"myLogo.png"
UIImage *titleImage = [UIImage imageNamed:Image_Macro]; UIImageView *titleImageView =[[UIImageView alloc] initWithImage:titleImage]; self.navigationItem.titleView = titleImageView;