2

I am reading the https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html working with blocks, and see following code:

void (^(^complexBlock)(void (^)(void)))(void) = ^ (void (^aBlock)(void))     {

    ...

    return ^{

        ...

    };

};

The above complexBlock variable refers to a block that takes another block as an argument (aBlock) and returns yet another block.

My question is that can I rewrite it as:

void (^) (void) (^complexBlock)(void (^)(void)) = ^ (void (^aBlock)(void))     {

    ...
    return ^{

       ...
    };
};

This makes it easier to understand right? I understand rewriting the code to use a type definition makes this much more readable, but my question is if don't use that, can I rewrite it this way? Many thank.

Huibin Zhang
  • 1,072
  • 1
  • 15
  • 30
  • 1
    it seems like you already know the answer, use a typedef! it compiles to the exact same thing, and is much more readable and less error prone. see my answer here: http://stackoverflow.com/questions/27162567/syntax-to-define-a-block-in-objective-c/27162860#27162860 – Nick Feb 01 '15 at 18:24
  • 5
    What does the compiler tell you? ;) – David Rönnqvist Feb 01 '15 at 18:25
  • "This makes it easier to understand right?” ... (a) it’s not valid; and (b) no, not remotely more readable. The typealias approach does, but not this. – Rob Jan 01 '19 at 17:31

0 Answers0