An Objective-C message rendered as an object.


@interface NSInvocation : NSObject


NSInvocation objects are used to store and forward messages between objects and between applications, primarily by NSTimer objects and the distributed objects system. An NSInvocation object contains all the elements of an Objective-C message: a target, a selector, arguments, and the return value. Each of these elements can be set directly, and the return value is set automatically when the NSInvocation object is dispatched.

An NSInvocation object can be repeatedly dispatched to different targets; its arguments can be modified between dispatch for varying results; even its selector can be changed to another with the same method signature (argument and return types). This flexibility makes NSInvocation useful for repeating messages with many arguments and variations; rather than retyping a slightly different expression for each message, you modify the NSInvocation object as needed each time before dispatching it to a new target.

NSInvocation does not support invocations of methods with either variable numbers of arguments or union arguments. You should use the invocationWithMethodSignature: class method to create NSInvocation objects; you should not create these objects using alloc and init.

This class does not retain the arguments for the contained invocation by default. If those objects might disappear between the time you create your instance of NSInvocation and the time you use it, you should explicitly retain the objects yourself or invoke the retainArguments method to have the invocation object retain them itself.


Creating NSInvocation Objects

+ invocationWithMethodSignature:

Returns an NSInvocation object able to construct messages using a given method signature.

Configuring an Invocation Object


The receiver’s selector, or 0 if it hasn’t been set.


The receiver’s target, or nil if the receiver has no target.

- setArgument:atIndex:

Sets an argument of the receiver.

- getArgument:atIndex:

Returns by indirection the receiver's argument at a specified index.


YES if the receiver has retained its arguments, NO otherwise.

- retainArguments

If the receiver hasn’t already done so, retains the target and all object arguments of the receiver and copies all of its C-string arguments and blocks. If a returnvalue has been set, this is also retained or copied.

- setReturnValue:

Sets the receiver’s return value.

- getReturnValue:

Gets the receiver's return value.

Dispatching an Invocation

- invoke

Sends the receiver’s message (with arguments) to its target and sets the return value.

- invokeWithTarget:

Sets the receiver’s target, sends the receiver’s message (with arguments) to that target, and sets the return value.

Getting the Method Signature


The receiver’s method signature.


Inherits From

See Also



A record of the type information for the return value and parameters of a method.