#ifdef DEBUG or similar

Discussion in 'iOS Programming' started by JimBobBennett, Jun 2, 2009.

  1. JimBobBennett macrumors member

    Joined:
    May 4, 2009
    #1
    I've got some code in my app that is for debugging purposes only, including resource files. Can anyone point me in the direction of some information about how to define debug only symbols so I can compile with and without my debug code, and how to specify that a resource only appiles to one configuration?

    I've tried googling it, but getting nowhere...

    Many thanks in advance!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. JimBobBennett thread starter macrumors member

    Joined:
    May 4, 2009
    #3
    Thanks - that sorts out how to define the preprocessor macros.
    Any ideas about resources only existing in one build?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    Define your own copy-file build phase for those resources and only add it to the build-type you want those resources in?
     
  5. JimBobBennett thread starter macrumors member

    Joined:
    May 4, 2009
    #5
    I've never head of the copy file build phase before - bit of an xcode newbie.
    I'll have a google and see what I can do. Thanks for all your help - sometimes us newbies just need a slight nudge in the right direction.
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    It's all in the XCode Documentation...
     
  7. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    my solution

    throw this code into your AppName_Prefix.pch file, and don't worry about setting a preprocessor macros in the target build (as some of those tutorials online suggest).

    Code:
    [COLOR="Green"]//Toggle DebugLog() Visibility[/COLOR]
    #define ShowDebugLogs 0
    
    [COLOR="green"]//DebugLog() Visibility[/COLOR]
    #if ShowDebugLogs
    #define DebugLog(…) NSLog(__VA_ARGS__)
    #else
    #define DebugLog(…)
    #endif
    
    [COLOR="green"]//ReleaseLog() Visibility[/COLOR]
    #define ReleaseLog(…) NSLog(__VA_ARGS__)
    
    in the example above, ShowDebugLogs is set to off (that's what the zero means). change the zero to one to turn it on - obviously. so anywhere in my code that has DebugLog(@"debug log example");, will not output. However, anywhere in my code that has ReleaseLog(@"release log example"); will always output, just like a regular NSLog() call.
     

Share This Page