Refer to this original Post by e.James

According to Apple’s NSInvocation class reference:

An NSInvocation is an Objective-C message rendered static, that is, it is an action turned into an object.

And, in a little more detail:

The concept of messages is central to the objective-c philosophy. Any time you call a method, or access a variable of some object, you are sending it a message. NSInvocation comes in handy when you want to send a message to an object at a different point in time, or send the same message several times. NSInvocation allows you to describe the message you are going to send, and then invoke it (actually send it to the target object) later on.


For example, let’s say you want to add a string to an array. You would normally send the addObject: message as follows:

[myArray addObject:myString];

Now, let’s say you want to use NSInvocation to send this message at some other point in time:

First, you would prepare an NSInvocation object for use with NSMutableArray’s addObject: selector:

NSMethodSignature * mySignature = [NSMutableArray
    instanceMethodSignatureForSelector:@selector(addObject:)];
NSInvocation * myInvocation = [NSInvocation
    invocationWithMethodSignature:mySignature];

Next, you would specify which object to send the message to:

[myInvocation setTarget:myArray];

Specify the message you wish to send to that object:

[myInvocation setSelector:@selector(addObject:)];

And fill in any arguments for that method:

[myInvocation setArgument:&myString atIndex:2];

Note that object arguments must be passed by pointer. Thank you to Ryan McCuaig for pointing that out, and please see Apple’s documentation for more details.

At this point, myInvocation is a complete object, describing a message that can be sent. To actually send the message, you would call: