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

# NSProxy

An abstract superclass defining an API for objects that act as stand-ins for other objects or for objects that don’t exist yet.

```
class NSProxy
```

## Overview

Typically, a message to a proxy is forwarded to the real object or causes the proxy to load (or transform itself into) the real object. Subclasses of [`NSProxy`](/documentation/Foundation/NSProxy) can be used to implement transparent distributed messaging (for example, [`NSDistantObject`](/documentation/Foundation/NSDistantObject)) or for lazy instantiation of objects that are expensive to create.

[`NSProxy`](/documentation/Foundation/NSProxy) implements the basic methods required of a root class, including those defined in the <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol> protocol. However, as an abstract class it doesn’t provide an initialization method, and it raises an exception upon receiving any message it doesn’t respond to. A concrete subclass must therefore provide an initialization or creation method and override the [`forwardInvocation(_:)`](/documentation/Foundation/NSProxy/forwardInvocation(_:)) and [`methodSignatureForSelector:`](/documentation/Foundation/NSProxy/methodSignatureForSelector:) methods to handle messages that it doesn’t implement itself. A subclass’s implementation of [`forwardInvocation(_:)`](/documentation/Foundation/NSProxy/forwardInvocation(_:)) should do whatever is needed to process the invocation, such as forwarding the invocation over the network or loading the real object and passing it the invocation. [`methodSignatureForSelector:`](/documentation/Foundation/NSProxy/methodSignatureForSelector:) is required to provide argument type information for a given message; a subclass’s implementation should be able to determine the argument types for the messages it needs to forward and should construct an [`NSMethodSignature`](/documentation/Foundation/NSMethodSignature) object accordingly. See the [`NSDistantObject`](/documentation/Foundation/NSDistantObject), [`NSInvocation`](/documentation/Foundation/NSInvocation), and [`NSMethodSignature`](/documentation/Foundation/NSMethodSignature) class specifications for more information.

## Topics

### Creating Instances

[`alloc()`](/documentation/Foundation/NSProxy/alloc())

Returns a new instance of the receiving class

[`allocWithZone:`](/documentation/Foundation/NSProxy/allocWithZone:)

Returns a new instance of the receiving class

### Deallocating Instances

[`dealloc()`](/documentation/Foundation/NSProxy/dealloc())

Deallocates the memory occupied by the receiver.

### Finalizing an Object

[`finalize()`](/documentation/Foundation/NSProxy/finalize())

The garbage collector invokes this method on the receiver before disposing of the memory it uses.

### Handling Unimplemented Methods

[`forwardInvocation(_:)`](/documentation/Foundation/NSProxy/forwardInvocation(_:))

Passes a given invocation to the real object the proxy represents.

[`methodSignatureForSelector:`](/documentation/Foundation/NSProxy/methodSignatureForSelector:)

Raises `NSInvalidArgumentException`. Override this method in your concrete subclass to return a proper `NSMethodSignature` object for the given selector and the class your proxy objects stand in for.

### Introspecting a Proxy Class

[`responds(to:)`](/documentation/Foundation/NSProxy/responds(to:))

Returns a Boolean value that indicates whether the receiving class responds to a given selector.

### Describing a Proxy Class or Object

[`class()`](/documentation/Foundation/NSProxy/class())

Returns `self` (the class object).

[`description`](/documentation/Foundation/NSProxy/description)

A string containing the real class name and the id of the receiver as a hexadecimal number.

[`debugDescription`](/documentation/Foundation/NSProxy/debugDescription)

A string containing a human-readable description of the receiver suitable for debugging.



---

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)