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

# getReturnValue:

Gets the invocation’s return value.

```
- (void) getReturnValue:(void *) retLoc;
```

## Parameters

`retLoc`

An untyped buffer into which the invocation copies its return value. It should be large enough to accommodate the value. See the discussion below for more information about `buffer`.

## Discussion

Use the `NSMethodSignature` method [`methodReturnLength`](/documentation/Foundation/NSMethodSignature/methodReturnLength) to determine the size needed for `buffer`:

```objc
NSUInteger length = [[myInvocation methodSignature] methodReturnLength];
buffer = (void *)malloc(length);
[invocation getReturnValue:buffer];
```

When the return value is an object, pass a pointer to the variable (or memory) into which [`NSInvocation`](/documentation/Foundation/NSInvocation) should place the object. In the following example, `myInvocation` represents a call to a no-argument method called `createReturnValue` in a class called `MyClass`, which returns an [`NSMutableString`](/documentation/Foundation/NSMutableString). The example performs the invocation with [`invoke`](/documentation/Foundation/NSInvocation/invoke), then retrieves the object with [`getReturnValue:`](/documentation/Foundation/NSInvocation/getReturnValue:) and copies it to a strongly-held property called `myObject`.

> Warning:
> ``doc://com.apple.foundation/documentation/Foundation/NSInvocation`` copies the return value directly into `buffer` without any memory bookkeeping, even when using Automatic Reference Counting (ARC). When using ARC, pass a pointer whose memory semantics match those expected by the method. Otherwise, an over-release crash may occur. For typical Objective-C methods, where ownership isn’t returned to the caller, use an `unsafe_unretained` variable. You can then copy this into another form of storage, like a strongly-held property. However, if the only thing keeping the returned value alive is the invocation’s ``doc://com.apple.foundation/documentation/Foundation/NSInvocation/target``, then you must keep the target alive while using the returned value. You can do this with the macro ``doc://com.apple.foundation/documentation/Foundation/NS_VALID_UNTIL_END_OF_SCOPE`` on the target. The following example shows how to properly manage memory when using ARC.

```objc
// Create invocation, set selector, and invoke.
NS_VALID_UNTIL_END_OF_SCOPE MyClass* myTarget = [[MyClass alloc] init];
NSMethodSignature* mySignature = [MyClass
    instanceMethodSignatureForSelector: @selector(createReturnValue)];
NSInvocation* myInvocation = [NSInvocation invocationWithMethodSignature: mySignature];
[myInvocation setSelector: @selector(createReturnValue)];

[myInvocation invokeWithTarget: myTarget];

// Retrieve return value and assign to property.
__unsafe_unretained id tempObject = nil;
[myInvocation getReturnValue: &tempObject];
self.myObject = tempObject;
```

If you haven’t invoked the [`NSInvocation`](/documentation/Foundation/NSInvocation) object, the result of this method is undefined.

## See Also

[`@property (readonly) const char * methodReturnType;`](/documentation/Foundation/NSMethodSignature/methodReturnType)

A C string encoding the return type of the method in Objective-C type encoding.



---

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)