Sign up ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is there anyway to delete the NSLog lines from the app by any trick/tool? I usually use NSLog's in each & every method to understand the flow of control & to know about the values of the app's variables. I also use lots of commend lines to explain the nature of methods and variables.

But, in some stage, these NSLog's & comment lines confusing the program understanding (It's to me). So I need to again & again deleting/creating this logs & comments. Is there a way to show/hide them by any trick in Xcode?

Thanks in advance

share|improve this question
This isn't directly a programing question; it's a question about how to use a Mac program (albeit one used exclusively by programmers). Questions about programming, development, and listing your apps on the App Store are off topic for Ask Different. This isn't exactly off-topic here, but you might be more likely to find answers in a forum for developers rather than this one for end users. – Daniel Jul 31 '12 at 5:20

1 Answer 1

up vote 3 down vote accepted

as a Dev, I can offer these two methods, although I agree with Daniel, that Stack Overflow is a better place to ask this.

Anyway, the first is a simple replace.

Shift-Option-f. Then type NSLog. That will find all the occurances of NSLog in your app.

Then switch find to replace. Then replace "NSLog" with "//NSLog". That will comment out all of them.

A second - better option takes a bit more work.

First, do the above but instead of replacing the string with "//NSLog", replace it with something like "DLog".

Then, in the prefix.pch file.. Write something like this:

#ifdef DEBUG
#    define DLog(...) NSLog(__VA_ARGS__)
#    define DLog(...) 
#define ALog(...) NSLog(__VA_ARGS__)

This way, while your app is in debug mode, all the logs will appear, but when you move your app to release mode, the logs are hidden.

Hope this helps.

share|improve this answer
Thank you.. In first case, we are commenting all logs and in the second case, we just print the logs before submitting app. Actually what I want is, the NSLog's and All comments should be removed from my code. So that I can understand the methods easily (It's for me. Because I can not concentrate when seeing lots of comments and logs) :( – Confused Aug 1 '12 at 9:48
Others can probably provide a script, but the easiest way for me (it's boring) is to do Shift-Option-F, search for "NSLog" and delete the line. It's probably about a half hour of work. – David DelMonte Aug 1 '12 at 11:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.