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?
Asked
Active
Viewed 2,916 times
2 Answers
11
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.

Don McCaughey
- 9,532
- 3
- 30
- 36
-
You can add variables to a category with [Associated Objects](http://nshipster.com/associated-objects/) – Adam Johns Oct 29 '14 at 18:52
7
A category of a class adds methods to that class. It cannot add instance variables.
If you need to add instance variables you may want to subclass instead.

mouviciel
- 66,855
- 13
- 106
- 140
-
3If you need to add instance variables, you can use associated objects. – Jacob Relkin Dec 31 '11 at 00:03