Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:47:28+00:00 2026-06-10T07:47:28+00:00

Update: More info on this here: Is it true that one should not use

  • 0

Update:

More info on this here:

Is it true that one should not use NSLog() on production code?

~~~~~~~~~~~~~~~~~~~~~~~~

Situation

I have some pretty beafy NSLog calls that I use for debugging the more complex parts of my application. However, I just recently learned that these affect runtime performance!

Goal

I would like to remove my NSLog calls during any run where I am not actually performing Product > Run (aka command-R) from within Xcode – ESPECIALLY in situations when this thing is deployed on the App Store, but also when I am running the app when disconnected from Xcode (i.e. just tapping the icon while walking down the street).

Proposed Solution?

Assuming I’ve created a Preprocessor Macro of VIEW_DEBUG, would the following implementation effectively remove NSLog calls from executing in the cases I’ve described above?

    <bunch of code>

#ifdef VIEW_DEBUG
    NSLog(@"really complex logs entries");
#endif

    <even more code>

This is a difficult one for me to ‘test’, so I figured I would appeal to more experienced minds. 🙂

Xcode Settings (for reference)

xcode settings

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:47:29+00:00Added an answer on June 10, 2026 at 7:47 am

    A common solution is to place the following code in your Prefix file (or you may create a dedicated class and #include it as needed):

    #ifdef DEBUG    
    #define DebugLog(...) NSLog(__VA_ARGS__)
    #else
    #define DebugLog(...) while(0)
    #endif
    

    Xcode already defines DEBUG for you when performing a debug build (as shown in your screenshot). VA_ARGS is a way of creating variadic macros that was introduced in C99. the do/while ensures that DebugLog
    has the same net syntactic effect even when it doesn’t do anything — don’t worry about the pointless loop, the optimiser will remove it for you.

    Then you can just use DebugLog exactly as you’d use NSLog. This will do exactly what you propose with VIEW_DEBUG but without you having to copy and paste the #ifdef condition a thousand times over.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to update more than one update statements, but all should work on
Update: After some more reading I see that this problem is totally general, you
UPDATE: I've been playing around with this more, and it seems like tmux's clear-history
I'm attempt to establish a grid and update it with more records via JSON.
I found some problem. When i running apc_store and more times update a page
Update: I've fixed up my referencing below, and my problem is now more specific.
UPDATED: Added one more question (Question #4). Hi all, I'm building myself a custom
Code is read more often then updated. Writing more readable code is better than
check this page out: http://jsbin.com/itufix with IE (page automatically enables IE7 mode). Here you'll
Imagine you have this model: class Category(models.Model): node_id = models.IntegerField(primary_key = True) type_id =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.