Tutorial: Instance Variables In Objective-C Categories

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.

.

DeliciousTwitterTechnoratiFacebookLinkedInEmail

Leave a Reply

Your email address will not be published. Required fields are marked *