objective c - Why does this method pass 'stop' by reference instead of return? -


does have insight why block parameter of

- (void)enumeratematchesinstring:(nsstring *)string                          options:(nsmatchingoptions)options                            range:(nsrange)range                       usingblock:(void (^)(nstextcheckingresult *result, nsmatchingflags flags, bool *stop))block 

passes stop reference instead of returning it?

it seems 'obvious' me use return value proabbly means missing , know missing. (the thing can think of able provide name pass reference variables make meaning clearer.)

my guess because stop functionality not needed, , making block return void keeps syntax lighter, because can fall off end of code return:

usingblock:^(nstextcheckingresult *result, nsmatchingflags flags, bool *stop) {     nslog(@"result: %@", result); }]; 

rather than:

usingblock:^(nstextcheckingresult *result, nsmatchingflags flags) {     nslog(@"result: %@", result);     return yes; }]; 

also, point out, there matter of clarity. without checking docs, hard tell return value means enumeration here. (also, speaking of block return values: where's -[nsarray collectresultsusingblock:] method?)

an added minor factor might bool types did not play block type inference while, this:

usingblock:^(nstextcheckingresult *result, nsmatchingflags flags) {     return yes; }]; 

would throw type error requiring either:

return (bool)yes; 

or:

usingblock:^bool (nstextcheckingresult… 

in order make work out right.

all of rank speculation. documentation appears silent on matter; coding guidelines cocoa not appear have been updated include standardization efforts apple appears have adopted internally, such providing names block arguments in prototype declarations.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -