Did You Know?

I must have missed the memo, but if you’ve registered your iOS device for development (in XCode), you have the ability to simulate network conditions right on your device.

20130521-003218.jpg

iOS Tips – NSLog()

Like young children — developers seldom remember to pick up after themselves when finishing a project. And while you might think that it’s not a big deal, you’d be wrong. As a developer leaving calls to NSLog() in your ‘Release’ code can significantly affect the performance of your iOS app.

Suppose that you’re developing an iOS app with a UIScrollView or UITableView. And within the scrollview’s delegate you place an NSLog() statement in the ‘scrollViewDidScroll’ method. This means that for every frame you have additional and unnecessary function calls which in turn consume CPU cycles.

Of course, no one likes cleaning up after themselves. So a quick and easy way to disable the NSLog calls in the ‘Release’ code is to define a wrapper macro for logging. What I do is define the following in my project’s .pch file

#ifdef DEBUG
#define DebugLog(…) NSLog(@“%s (%d) %@”, __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])
#else
#define DebugLog(…)
#endif