Say we have this block:
int (^aBlock)(BOOL) = ^(BOOL param) { ...
My current understanding of this is: the first int is the return type, (^aBlock)(BOOL) gives the name of the method and the type of its parameter, and = ^(BOOL param) is the parameter’s name inside the block … plus the parameter’s type again?
Why is the syntax such that we have to list the parameter type twice? Could the two types ever be different?
It is not quite “listing the parameter type twice”, you are in the first case declaring the type of a block variable, and in the second case you are defining a block literal.
Then you are assigning the literal to the value of the variable. You could even do something like this, which is equivalent and better illustrates the fact that these are really two totally independent declarations, despite being associated with an assign statement:
The fact that they are independent of each other means it’s probably not even correct to attempt to provide some kind of transference or inheritance of typing information from the left hand side of the expression to the right. And yes, the types can be different – consider this code compiles and executes just fine:
Hope this helps!