typedef does not define a "real" type. It is basically like a macro that expands wherever it is used. Therefore, typedef cannot be recursive.
Another way to think about the fact that typedef never required is that you can always take any piece of code with typedef and just replace every appearance with a base type (what the compiler does when you compile), and it will always work and be completely equivalent . Think about it - how would you do it without a typedef ? You can not. Thus, you cannot do this with typedef .
The only ways to do this: use id as the argument type to erase the type, as you do; or, encapsulate a block inside a "real" type of type struct or class. However, if you do this last, you must explicitly place the block and extract the block from the structure or class, which makes the code confusing. In addition, struct dangerous because struct is a scalar C-type, and if you need to capture it with a block, it does not automatically manage the memory of objects inside the structure. As for the class, the definition of the packaging class is very verbose, and using it for this causes the selection of an extraneous fictitious object for each block that it wraps.
In my opinion, using id as you use is fine and is the cleanest way. However, keep in mind that if you want this block to be passed as id , captured by another internal block, you must return it to the type of the block before it is captured, since the capture semantics are different for the block and another object types (blocks are copied, while others objects are saved). Just return it to the block type in the earliest place.
source share