Here's a guess:
Category is implemented by attaching additional slots at the tail of the vtbl (virtual function table). It's based on the fact that there's only one copy of vtbl for a class - if we define a category, the compiler could extend the vtbl for several slots for the newly added member functions.
* Why can't category add ivar?
Because for the well-known class like NSObject, all the libraries may use it as base class - and they're in binary. We have no way to change the layout of the object for compiled code.
So it's not able to simulate multi-inheritance gracefully.
No comments:
Post a Comment