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.

Learn how to program an iOS app using Objective-C right from the start with The iOS Apprentice series. A set of epic tutorials for anyone - even if you've never programmed before.
Read more...
DeliciousTwitterFacebookLinkedInEmail

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can send a Tweet to @maniacdev on Twitter or submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Click on a tab to select how you'd like to leave your comment

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>