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?
Why is the syntax such that we have to list the parameter type twice?
The block is designed in this way, and so you can do it like this:
int (^aBlock)(BOOL);
aBlock = ^(BOOL param) {
...
};
It just likes
- (int)aMethodWithParam:(BOOL)param;
- (int)aMethodWithParam:(BOOL)param {
...
}
Could the two types ever be different?
Nope, and what's more, the order of the types should be the same, i.e.:
int (^aBlock)(BOOL, NSString*) = ^(BOOL param, NSString *aString) {
...
};
And here's a clear figure for block:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With