Leaving NSLog code on iOS apps


#1

What happens to NSLog code of an iOS app when the device isn’t connected and logging in the console?
Does the device still runs the code, or does it ignore console commands?
Is there a performance hit if I leave NSLog commands on my iOS apps?

I did a search on StackOverflow, but couldn’t find an exact answer to all these questions. (Only one person saying there is a performance hit)

Thanks


#2

It does cause a performance hit from what I have seen. You can either remove them all (a lot of work) or use a conditional #define to remove them with the preprocessor.


#3

I’m not totally convinced, but I haven’t tested for myself. There are a lot of ways to test that could lead to false positives, so I won’t be taking anyone at the word either.

Either way, you can define your own logging function like so:

#define MyLog NSLog

And then when you deploy, you can just change that macro to be nothing:

#define MyLog

There are safer ways of doing this, but that’ll work well enough.