ObjectiveMixin
ObjectiveMixin copied to clipboard
Question about the Ninja Turtle example
Even though the clanName instance variable does not exist in Turtle's definition, it is synthesized at runtime in the turtle object, and everything works fine.
This confuses me a lot. I know of no mechanisms that allow to add ivar at run-time. In fact, it is impossible since it would mean dynamically changing the size of all objects of a certain class.
Now, you can use the runtime to add "associated objects", but the implementation doesn't do that. In fact, it simply copies methods from the mixin to the target class.
I remember stumbling on a similar case once, and the tricky thing was that it failed silently: it used the storage of the first instance variable of the destination object as storage for the property declared in the protocol (using the same approach as in the mountain bike exemple).
So, are you sure this works? If it does, I'd love some enlightening :)