nuteron
nuteron

Reputation: 541

Remove all NSLogs in Xcode at once

Am currently creating a demo drawing and image editing app just for a practice. Have created few custom views and doing my drawings using draw rect. Thing is i keep writing NSLogs to check my points and contents of other objects frequently and i dont remove many of them, since i need them again and again. But observing that the logs are eating up processing time and making some of the drawing process laggy.

My question is, is there any method in xcode to remove all NSlogs at once while launching the app and add them again while testing.

Upvotes: 0

Views: 574

Answers (3)

nuteron
nuteron

Reputation: 541

found one more good way of doing it, by defining your custom NSLog, using a macro like this: MYLog(@"Count of student array-->%d",[studentArray count]);

And in your app-prefix.h file, which holds the common headers for all your files in the project define the 'MYLog' macro this way:-

#ifdef DEBUG

#define MYLog(f, ...) NSLog( @"<%@:(%d)> %@",[[NSString stringWithUTF8String:_FILE _] lastPathComponent], _LINE _, [NSString stringWithFormat:(f), ##_VA_ARGS _] )

#else

#define MYLog(f, ...)

#endif

So when you need to test, put your project in debug mode and when you need to run without the logs put your project in release mode. Simple.. ps FILE AND LINE are macros executed py the preprocessor to print the file name and line no in which the log is present. Try it out..

Upvotes: 0

nuteron
nuteron

Reputation: 541

Hi One method that i came to know is using the Find and replace option in xcode.
ie. say for eg you need to remove all NSLogs you have written in your entire project.
Find for the NSLog keyword in whole project (cmd+shift+F), then replace it with //NSLog. This would comment out all the NSLogs you have written.
When you need to uncomment the logs just do the opposite.
ie Find for the //NSLog keyword in whole project (cmd+shift+F), then replace it with NSLog. This would uncomment out all the NSLogs you have written and they print in the console again. You can do this for particular files also by using just (cmd+F) instead of (cmd+shift+F).. But not sure if xcode actually has a proper method to do this.

Upvotes: 0

mayuur
mayuur

Reputation: 4746

Do something like this...

Click Command+Shift+F

Select Replace

enter image description here

And replace NSLog with //NSLog

Not so good solution, but still works! :)

Upvotes: 2

Related Questions