What is the difference between NSInvocation and block?

when I say that block i means:

^(int a) {return a*a;};

In addition, the block only supports iOS4 and higher.

What is the difference between the two?

+5
source share
3 answers

An NSInvocationis a message (using a selector) for an object with optional parameters that can be executed later (or now) and outside the current context (of course, that you copy or save or refer if you move it). NSInvocationhas the advantage that you can selectively copy / reference exactly what you need.

, . , NSInvocation, , ( ). , . (, ), - NSInvocation.

+3

NSInvocation - , : , , . - , , : , .

: - , . , . , , . , .

+3

Simply put, NSInvocationless powerful than blocks. It simply encapsulates one method call per object, while blocks can wrap multiple lines of arbitrary code. Even your very simple quadratic block cannot be represented by a call without supporting an existing class that could perform squaring.

0
source

All Articles