<!--
{
  "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/setArgument:atIndex:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSInvocation(im)setArgument:atIndex:"
  },
  "title" : "setArgument:atIndex:"
}
-->

# setArgument:atIndex:

Sets an argument of the receiver.

```
- (void) setArgument:(void *) argumentLocation atIndex:(NSInteger) idx;
```

## Parameters

`argumentLocation`

An untyped buffer containing an argument to be assigned to the receiver. See the discussion below relating to argument values that are objects.

`idx`

An integer specifying the index of the argument.

    Indices 0 and 1 indicate the hidden arguments     `self`     and     `_cmd`    , respectively; you should set these values directly with the [`target`](/documentation/Foundation/NSInvocation/target)     and [`selector`](/documentation/Foundation/NSInvocation/selector)     properties. Use indices 2 and greater for the arguments normally passed in a message.

## Discussion

This method copies the contents of `buffer` as the argument at `index`. The number of bytes copied is determined by the argument size.

When the argument value is an object, pass a pointer to the variable (or memory) from which the object should be copied:

```objc
NSArray *anArray;
[invocation setArgument:&anArray atIndex:3];
```

This method raises `NSInvalidArgumentException` if the value of `index` is greater than the actual number of arguments for the selector.

## See Also

[`@property (readonly) NSUInteger numberOfArguments;`](/documentation/Foundation/NSMethodSignature/numberOfArguments)

The number of arguments recorded in the receiver.



---

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)