I'm a beginner to Objective C and iOS development, but a 13-year .NET veteran. I'm having a hard time mentally diagramming the following declaration, which came from the Programming with Objective C guide:
void (^(^a)(void (^) (void))) (void) = ...
It's used as an example of why one should use typedef
to define blocks, but I want to understand what I'm looking at to better get a feel for block definition syntax in the first place.
Here's how I've diagrammed it so far:
Where I'm running into problems is that here is how I understand the basic syntax:
[return_val] (^[block_name]) ([block_args]) = ...
If that's the case, then what I have is a block that returns void and has no arguments, but is named (^a) (void (^) void)
. Meaning the name of my block, rather than being a straight string, is itself a block.
Clearly I'm missing something here. Can someone please shed some light on it? According to the site, it simplifies to this:
typedef void (^SimpleBlock) (void);
SimpleBlock (^complexBlock) (SimpleBlock) = ...
I'm just missing how.
Edit: The third void should have been in parentheses. I fixed that. It's wrong in the image, but I didn't feel like redoing the entire image just for that. :) If it turns out to be the source of my problem, I will fix it here.
void (^(^a)(void (^) void)) (void)
is correct? Shouldn't the 3rdvoid
be in parentheses? Where in the link you referenced is this frmm? – rmaddy