Sunday, September 1, 2013

Objective-C MACRO #define

So of my favorite macro I use in most of my projects are as follows

From NSScreenCast
 #define URLIFY(urlString) [NSURL URLWithString:urlString]  
 #define F(string, args...) [NSString stringWithFormat:string, args]  
 #define ALERT(title, msg) [[[UIAlertView alloc]     initWithTitle:title\  
                             message:msg\  
                             delegate:nil\  
                             cancelButtonTitle:@"OK"\  
                             otherButtonTitles:nil] show]  


Text Alighment to support iOS 5 and iOS 6
 #ifdef __IPHONE_6_0  
   # define ALIGN_CENTER NSTextAlignmentCenter  
 #else  
   # define ALIGN_CENTER UITextAlignmentCenter  
 #endif  
 #ifdef __IPHONE_6_0  
   # define ALIGN_RIGHT NSTextAlignmentRight  
 #else  
   # define ALIGN_RIGHT UITextAlignmentRight  
 #endif  
 #ifdef __IPHONE_6_0  
   # define ALIGN_LEFT NSTextAlignmentLeft  
 #else  
   # define ALIGN_LEFT UITextAlignmentLeft  
 #endif  


My Personal Macro's
 #define GOBACK [self.navigationController popViewControllerAnimated:YES]  
 #define DELEGATE_OK(delegateMethod) [self.delegate respondsToSelector:@selector(delegateMethod)]  


For Screen Size after Orientation Change

 #define SCREEN_WIDTH ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.width : [[UIScreen mainScreen] bounds].size.height)  
 #define SCREEN_HEIGHT ((([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait) || ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)) ? [[UIScreen mainScreen] bounds].size.height : [[UIScreen mainScreen] bounds].size.width)  

And some funny One from

Funny C/C++ declarations

http://www.gnu.org/fun/jokes/declarations.html




No comments:

Post a Comment