Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does a category work?

Tags:

objective-c

I'm new to objective-c and need to extend a standard class of a framework with an instance variable plus accessors. I heard that this is done with a so called "category", which sounds pretty confusing to me. How does this basically work?

like image 999
Thanks Avatar asked May 14 '09 09:05

Thanks


1 Answers

A category adds methods to the table of methods inside a class. It's very handy for adding application specific methods to existing framework classes.

If you need to add instance variables to a class, a category won't do the job -- categories only add methods, not data. To add instance variables, you must subclass.

like image 72
Don McCaughey Avatar answered Nov 15 '22 05:11

Don McCaughey