Function Object - in Objective-C

In Objective-C

In Objective-C a function object can be created from the NSInvocation class. Construction of a function object requires a method signature, the target object, and the target selector. Here is an example for creating an invocation to the current object's myMethod:

// Construct a function object SEL sel = @selector(myMethod); NSInvocation* inv = [NSInvocation invocationWithMethodSignature: ]; ; ; // Do the actual invocation ;

An advantage of NSInvocation is that the target object can be modified after creation. A single NSInvocation can be created and then called for each of any number of targets, for instance from an observable object. An NSInvocation can be created from only a protocol, but it is not straightforward. See here.

Read more about this topic:  Function Object