8

I have an Xcode project which has lots of NSLog statementS.

I have to submit my app to get approval from Apple, and I would like to remove all NSLog statementS which I had used for debugging.

I want to remove only NSLog statements.

5
  • but if we use the regular expression in xcode find & replace by selecting regular expression textbox in that,we can select all the NSlog statements.but i want to know that how to specify regular expression for NSLog(...);. Commented Apr 2, 2011 at 8:47
  • Your question is still not clear can you please post some code which can make us understand better? Commented Apr 2, 2011 at 8:50
  • NSLog\(.*\);\n$? But it f*** up indention. Commented Apr 2, 2011 at 8:52
  • hey PARTH ankit is right by through this we can delete all NSLog statements in out project .any way thanku for care Commented Apr 2, 2011 at 8:55
  • Have a look at this answer here... stackoverflow.com/a/12382047/1463604 Commented Sep 25, 2013 at 17:35

3 Answers 3

13

In Xcode, you can use Find and Replace and provide a regular expression something like:

NSLog.*;
Sign up to request clarification or add additional context in comments.

Comments

8

Put this in your prefix header......

   #ifndef __OPTIMIZE__

    #    define NSLog(...) NSLog(__VA_ARGS__)

      #else

     #    define NSLog(...) {}

      #endif

2 Comments

hey buddy thanks.but NSLog.*; this one is very handy.anyway thanks for ur answer
This method is MUCH more useful than NSLog.*; because I can keep all my logs but suppress their output for the distribution binary.
1

You can remove your NSLog statements using sed and grep. The basic idea is to grep all lines containing NSLog statements and then delete them using sed.

Using sed and grep might be new to you, but it's very helpful in the long run!

Here's some code I think should work, but backup your work first: grep -Ev 'NSLog'.

1 Comment

Dear @ryyst, I would not appreciate a technique that is irreversible & backup dependent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.