dbl-da
Last Updated: February 25, 2016
·
2.863K
· jfsagasti
U1b6bd8ad071161fb5bd43535867f4590

Useful macros for iOS projects

I usually use a bunch of macros which makes my life easier when developing iOS apps. I hope you find it as useful as I do!


Macros collection, found it at: https://gist.github.com/numo16/3407652


Aditionally, I use these macros to help me to debug (instead of using NSLog):

  • DLog will output like NSLog only when the DEBUG variable is set.
  • ALog will always output like NSLog.
  • ULog will show the UIAlertView only when the DEBUG variable is set.

    #ifdef DEBUG
        #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
        #define DLog(...)
        #define NSLog(...)
    #endif
    
    #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    
    #ifdef DEBUG
        #define ULog(fmt, ...)  { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__]  delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
    #else
        #define ULog(...)
    #endif

I found it at: http://stackoverflow.com/questions/969130/how-to-print-out-the-method-name-and-line-number-and-conditionally-disable-nslog

Say Thanks
Respond