<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDistantObject",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDistantObject"
  },
  "title" : "NSDistantObject"
}
-->

# NSDistantObject

A proxy for objects in other applications or threads.

```
@interface NSDistantObject : NSProxy
```

## Overview

When a distant object receives a message, in most cases it forwards the message through its [`NSConnection`](/documentation/Foundation/NSConnection) object to the real object in another application, supplying the return value to the sender of the message if one is received, and propagating any exception back to the invoker of the method that raised it.

[`NSDistantObject`](/documentation/Foundation/NSDistantObject) is a concrete subclass of [`NSProxy`](/documentation/Foundation/NSProxy), adding two useful instance methods of its own: [`connectionForProxy`](/documentation/Foundation/NSDistantObject/connectionForProxy) returns the [`NSConnection`](/documentation/Foundation/NSConnection) object that handles the receiver; [`setProtocolForProxy:`](/documentation/Foundation/NSDistantObject/setProtocolForProxy:) establishes the set of methods the real object is known to respond to, saving the network traffic required to determine the argument and return types the first time a particular selector is forwarded to the remote proxy.

There are two kinds of distant object: local proxies and remote proxies. A local proxy is created by an [`NSConnection`](/documentation/Foundation/NSConnection) object the first time an object is sent to another application. It is used by the connection for bookkeeping purposes and should be considered private. The local proxy is transmitted over the network using the [`NSCoding`](/documentation/Foundation/NSCoding) protocol to create the remote proxy, which is the object that the other application uses. [`NSDistantObject`](/documentation/Foundation/NSDistantObject) defines methods for an [`NSConnection`](/documentation/Foundation/NSConnection) object to create instances, but they’re intended only for subclasses to override—you should never invoke them directly. Use the [`rootProxyForConnectionWithRegisteredName:host:`](/documentation/Foundation/NSConnection/rootProxyForConnectionWithRegisteredName:host:) method of [`NSConnection`](/documentation/Foundation/NSConnection), which sets up all the required state for an object-proxy pair.

> Important:
> ``doc://com.apple.foundation/documentation/Foundation/NSDistantObject`` 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/NSDistantObject`` and its subclasses do not support archiving.

## Topics

### Creating a Local Proxy

[`proxyWithLocal:connection:`](/documentation/Foundation/NSDistantObject/proxyWithLocal:connection:)

Returns a local proxy for a given object and connection, creating the proxy if necessary.

[`initWithLocal:connection:`](/documentation/Foundation/NSDistantObject/initWithLocal:connection:)

Initializes an `NSDistantObject` object as a local proxy for a given object.

### Creating a Remote Proxy

[`proxyWithTarget:connection:`](/documentation/Foundation/NSDistantObject/proxyWithTarget:connection:)

Returns a remote proxy for a given object and connection, creating the proxy if necessary.

[`initWithTarget:connection:`](/documentation/Foundation/NSDistantObject/initWithTarget:connection:)

Initializes a newly allocated NSDistantObject as a remote proxy for `target`, which is an id in another thread or another application’s address space.

### Getting a Proxy’s NSConnection

[`connectionForProxy`](/documentation/Foundation/NSDistantObject/connectionForProxy)

Returns the connection used by the receiver.

### Setting a Proxy’s Protocol

[`setProtocolForProxy:`](/documentation/Foundation/NSDistantObject/setProtocolForProxy:)

Sets the methods known to be handled by the receiver to those in a given protocol.



---

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)