<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSInvocation",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSInvocation"
  },
  "title" : "NSInvocation"
}
-->

# NSInvocation

An Objective-C message rendered as an object.

```
@interface NSInvocation : NSObject
```

## Overview

[`NSInvocation`](/documentation/Foundation/NSInvocation) objects are used to store and forward messages between objects and between applications, primarily by [`Timer`](/documentation/Foundation/Timer) objects and the distributed objects system. An [`NSInvocation`](/documentation/Foundation/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`](/documentation/Foundation/NSInvocation) object is dispatched.

An [`NSInvocation`](/documentation/Foundation/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`](/documentation/Foundation/NSInvocation) useful for repeating messages with many arguments and variations; rather than retyping a slightly different expression for each message, you modify the [`NSInvocation`](/documentation/Foundation/NSInvocation) object as needed each time before dispatching it to a new target.

[`NSInvocation`](/documentation/Foundation/NSInvocation) does not support invocations of methods with either variable numbers of arguments or `union` arguments. You should use the [`invocationWithMethodSignature:`](/documentation/Foundation/NSInvocation/invocationWithMethodSignature:) class method to create [`NSInvocation`](/documentation/Foundation/NSInvocation) objects; you should not create these objects using <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/alloc> and <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/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`](/documentation/Foundation/NSInvocation) and the time you use it, you should explicitly retain the objects yourself or invoke the [`retainArguments`](/documentation/Foundation/NSInvocation/retainArguments) method to have the invocation object retain them itself.

> Note:
> ``doc://com.apple.foundation/documentation/Foundation/NSInvocation`` conforms to the ``doc://com.apple.foundation/documentation/Foundation/NSCoding`` protocol, but only supports coding by an ``doc://com.apple.foundation/documentation/Foundation/NSPortCoder``. ``doc://com.apple.foundation/documentation/Foundation/NSInvocation`` does not support archiving.

## Topics

### Creating NSInvocation Objects

[`invocationWithMethodSignature:`](/documentation/Foundation/NSInvocation/invocationWithMethodSignature:)

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

### Configuring an Invocation Object

[`selector`](/documentation/Foundation/NSInvocation/selector)

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

[`target`](/documentation/Foundation/NSInvocation/target)

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

[`setArgument:atIndex:`](/documentation/Foundation/NSInvocation/setArgument:atIndex:)

Sets an argument of the receiver.

[`getArgument:atIndex:`](/documentation/Foundation/NSInvocation/getArgument:atIndex:)

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

[`argumentsRetained`](/documentation/Foundation/NSInvocation/argumentsRetained)

A Boolean value that indicates if the receiver has retained its arguments.

[`retainArguments`](/documentation/Foundation/NSInvocation/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:`](/documentation/Foundation/NSInvocation/setReturnValue:)

Sets the receiver’s return value.

[`getReturnValue:`](/documentation/Foundation/NSInvocation/getReturnValue:)

Gets the invocation’s return value.

### Dispatching an Invocation

[`invoke`](/documentation/Foundation/NSInvocation/invoke)

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

[`invokeWithTarget:`](/documentation/Foundation/NSInvocation/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

[`methodSignature`](/documentation/Foundation/NSInvocation/methodSignature)

The receiver’s method signature.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)