2

I have NSLogs in code, so many time. A easy solution is that I replace with

NSLog(@  with //NSLog(@

But, If I want to remove all the lines, starting with NSLog, what can I do?

Thanks

Chatar Veer Suthar
  • 15,541
  • 26
  • 90
  • 154

3 Answers3

1

If your NSLogs are written in a single line, you can do a regex search and replace. Enter NSLog.*$ as the search regex and replace it with an empty string. All your NSLog statements should disappear.

marosoaie
  • 2,352
  • 23
  • 32
1

In Xcode just search and replace from the Project Navigator. You can select "Starting with", "Contains", "Regular Expression", etc.

Using Regular Expression ^[\s\W]+NSLog.*$ should work well for lines that might have a tab or space before the NSLog but won't catch lines with other text that may be in front of it. (notice in the second screen shot NSLog was detected at the end of the line, while the first didn't).

Another example might be if you want to keep commented NSLog lines and remove the others:

^[^/*]*[\s\t]*NSLog.*$ 

Would remove NSLog on line 3 and NSLog(@"%@",removed); on line 7.

// NSLog
/* NSLog */
NSLog

NSString *NSLog = @"not nslog"

    NSLog(@"%@",removed);

Additional Examples:

enter image description here enter image description here enter image description here

l'L'l
  • 44,951
  • 10
  • 95
  • 146
1

Add the following lines to your ConvenienceMethods file:

#define SHOWLOGS NO
#defile NSLog if(SHOWLOGS)NSLog

If you don't have ConvenienceMethods file just write it on your controllers.

Amit Pandey
  • 156
  • 2
  • 11