문제

The question says it all. Why:

(void)methodWithParamA:(id)paramA paramB:(id)paramB;
[obj methodWithParamA:valA paramB:valB];

and:

void(^ block)(id paramA, id paramB);
block(valA, valB);

I'm not sure I'll necessarily gain anything by learning the answer to this question, but I'm baffled that one language can have so many disparate syntaxes...

도움이 되었습니까?

해결책

A block is a function, there is no "current instance" (or "current class" for call methods) as with a method.

A block call therefore looks like a function call; a "block" type is a pointer type and follows very closely the syntax for function pointer types; and a block body follows closely the syntax of a function body.

Blocks are supported in C, which has functions but not methods.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top