Custom objects as NSDictionary keys

This post describes what is needed for any class to work as a key of NSDictionary or NSMutableDictionary. The only thing that is really required is that your class adopt the NSCopying protocol.  That’s because every key is copied before being added to the dictionary.  I mention why this design decision was probably made below. […]

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 […]

Event tracking stops NSTimer

NSTimers usually don’t fire when the user is scrolling a table or other UIScrollView – or doing anything else that puts the run loop in event tracking mode.  This post describes the problem and an easy solution. The problem Suppose you set up a timer in the most convenient manner, with something like this: [NSTimer […]

Memory management guidelines

In this post, I’ll outline four simple rules for memory management in Objective-C. The Apple docs have already established basic guidelines for object ownership, following the fundamental idea that if you own an object, then you’re responsible for releasing it. This post goes a step further with tips for when and where ownership can be […]

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 […]

Fun with layers