Class extension vs class category

AWF4vk picture AWF4vk · Aug 21, 2011 · Viewed 59.1k times · Source

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?

Answer

jtbandes picture jtbandes · Aug 21, 2011

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.