Reputation: 32066
I've just read this snippet from another answer:
When you create a block with the
^{}
syntax...
I understand this syntax, and use it regularly, however I inferred from this that there might be other syntaxes that can be used for creating blocks. Are there? If there are, are there any advantages of the different syntaxes?
Upvotes: 7
Views: 2136
Reputation: 33428
If your question is about block literal syntax (the one used for anonymous functions), here is the general form
^ return type (arguments list) {expressions}
Based on the that, you can omit the return type
^ (arguments list) {expressions}
since it can be inferred from the return type. If there is no return value, void
is the choice.
Furthermore, you can write
^ {expressions}
if there are no arguments.
This is the same as
^ void (void) { NSLog(@"Something"); }
Upvotes: 12