I will preface this question by stating that what I am about to ask is for educational and possibly debug purposes only.
How are block objects created internally in the Objective C runtime?
I see the hierarchy of classes that all represent various block types, and the highest superclass in the hierarchy, below NSObject
, is NSBlock
. Dumping for class data shows that it implements the + alloc
, + allocWithZone:
, + copy
and + copyWithZone:
methods. None of the other block subclasses implement these class methods, which leads me to believe, perhaps mistakenly, that NSBlock
is responsible for block handling.
But these methods seem not to be called at any point during a block's life time. I exchanged implementations with my own and put a breakpoint in each, but they never get called. Doing similar exercise with NSObject
's implementations gives me exactly what I want.
So I assume blocks are implemented in a different manner? Anyone can shed a light on how this implementation works? Even if I cannot hook into the allocation and copying of blocks, I would like to understand the internal implementation.
[NSBlock alloc]
to create a block, thats why they are not called.