Categories in Objective-C are very useful allowing you to add methods to existing classes without the need to extend those classes. This is extremely useful – but what if you needed to add an instance variable to the class?
With associative references it is possible to fake instance variables in your Objective-C categories thus making categories a much more useful feature.
Ole Begemann has written a tutorial demonstrating this functionality by demonstrating this principle with a UIView category.
You can find the tutorial on his website here:
Faking Instance Variables In Obj-C Categories
A very useful tip which can make for some much cleaner code.
©2011 iPhone, iOS 4, iPad SDK Development Tutorial and Programming Tips. All Rights Reserved.
.





