2

I want to know exactly, how to write a function that return block. Block syntax weird, as you know. The best solution i find, is following:

typedef void(^MyAwesomeBlock)(void);

MyAwesomeBlock blockFunction()
{
    MyAwesomeBlock block = ^{
        //some code;
    };

    return block;
}

Yeah, awesome, it work with typedef and it pretty neat, but, how to write correctly the same function without it?

I could put here a code that i tried, but i think that is no reason to do so, because it's just warn me with compiler errors all time.

Would you be so kind, to show me solution without typedef? Just a typical function, that return block. Thanks.

Trying following not work as well. enter image description here

Evgeniy Kleban
  • 6,794
  • 13
  • 54
  • 107
  • 1
    @robertvojta The other question asks about a *method*, while OP wants a *function*. It does not look like Objective-C provides a proper syntax for what OP wants to do. – Sergey Kalinichenko Jul 07 '15 at 14:38
  • @robertvojta i have seen that question, yes, but i still cant figure out how to do this with correct syntax.. – Evgeniy Kleban Jul 07 '15 at 14:38
  • 1
    @dasblinkenlight good catch, retracted my close vote ... – zrzka Jul 07 '15 at 14:41
  • @robertvojta very nice one, and i agreed, without typedef those round brackets could make your brain melting.. – Evgeniy Kleban Jul 07 '15 at 14:49
  • 1
    @EvgeniyKleban it could, but it's not that hard. Several rules described in [another answer](http://stackoverflow.com/a/89100/581190) and this shouldn't be a big issue. But for the readability sake, stick with `typedef` :-) – zrzka Jul 07 '15 at 18:06
  • @robertvojta yeah sure, but typedef is just kind of abstraction, its always good to know how things look under the hood ;) – Evgeniy Kleban Jul 07 '15 at 22:00

0 Answers0