Class extensions @interface Class ()
are a lot more powerful and can inject variables into the class. Categories @interface Class (Category)
can't.
What other differences are there, and when should one use a category over a class extension?
The main difference is that with an extension, the compiler will expect you to implement the methods within your main @implementation
, whereas with a category you have a separate @implementation
block. So you should pretty much only use an extension at the top of your main .m
file (the only place you should care about ivars, incidentally) -- it's meant to be just that, an extension.