Category Archives: debugging

Unresponsive UI

Here are some tips for debugging unresponsive UI elements, such as a UIButton or UISlider. These tips work for me at least 90% of the time I have this problem, which is great because there are many possible causes. Use recursiveDescription The single most useful advice here is to use the undocumented API call [UIView […]

Debug reference counting for any class

In a previous post, I mentioned a trick that I sometimes use to debug memory issues where a class I own is either being released too soon (often resulting in a EXC_BAD_ACCESS exception), or is leaked, resulting in low memory. The main idea was to temporarily override key methods such as retain, release, and autorelease […]

Print a stack trace anytime

Here’s how to print a stack trace from code at any point in your app – no need to wait for a crash report! – NSLog(@"%@", [NSThread callStackSymbols]); That requires iOS 4.0+. There are some easy-to-use C functions that do the same thing: #import <execinfo.h> #import <unistd.h> void PrintStackTrace() {   void *stackAdresses[32];   int […]

Clash-happy method names

This post lists a few special-case method names that are somewhat likely to be used accidentally by you but can only be used correctly if you understand their built-in functions.  Specifically: class, description, load, and hash. Why it’s tricky, by example Here’s an easy way to mess this up: start with a model object meant […]

UIScrollView bug

This post describes a bug in UIScrollView that occurs when you programmatically set the contentOffset with animation. Below is code to reproduce the bug; I’ve confirmed it’s in iPhone OS 3.2 but it may be in other versions as well. If you make a call to [scrollView setContentOffset:offset1 animated:YES]; and later make a call to […]

Preprocessor debugging goodies

Ok, I admit it – my favorite debugging tool is still NSLog (and print statements in general).  In this post I’ll mention some useful debug logging techniques you can use with the help of preprocessor macros. Logging method calls It’s as simple as this: #define PrintName NSLog(@”%s”, __FUNCTION__) Add this macro (with a semicolon) to […]

feeling retained?

This is a quick tip for figuring out why an object is not being released when you expect it to: For the object in question, override retain and release to log their activity. Don’t forget that alloc is always called first, so if you see an equal number of retain and release logs, this means […]