Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all NSLog statements in a file using a regular expression with the Xcode Find & Replace option

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.

like image 865
Vijay-Apple-Dev.blogspot.com Avatar asked Apr 02 '11 08:04

Vijay-Apple-Dev.blogspot.com


3 Answers

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

NSLog.*;
like image 88
Ankit Bansal Avatar answered Oct 23 '22 09:10

Ankit Bansal


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

   #ifndef __OPTIMIZE__

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

      #else

     #    define NSLog(...) {}

      #endif
like image 8
Abhishek Bedi Avatar answered Oct 23 '22 09:10

Abhishek Bedi


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'.

like image 1
ryyst Avatar answered Oct 23 '22 08:10

ryyst