开发者

Why most block use argument for iteration continue flag instead of return value?

For most iteration开发者_开发百科 blocks, signatures are defined sort of:

void(^)(id obj, BOOL* stop)

It looks better using return value for stopping flag.

BOOL(^)(id obj)

However I believe there is a strong reason made them to decide to use current form instead of more short and convenient form. Why do they use argument for stop flag?


Sure, it would work fine either way, but think of it this way: do you have to use the continue statement at the end of your for or while loop? No, of course not because it happens automatically. If you want to stop looping though, you can just use break.

Similarly with the block-based enumeration methods. You're not required to return YES to specify whether you want to continue enumeration or not because it will happen automatically. However, if you want to stop enumerating, you can simply set *stop to YES.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜