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

# 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.

```
- (instancetype) initWithTarget:(id) target connection:(NSConnection *) connection;
```

## Parameters

`target`

An object in another thread or another application’s address space.

`connection`

The connection to set as the `NSConnection` object for the returned proxy—it should have been created using the [`connectionWithRegisteredName:host:`](/documentation/Foundation/NSConnection/connectionWithRegisteredName:host:) class method.

## Return Value

An `NSDistantObject` object initialized as a remote proxy for `target`. If a proxy for `target` and `connection` already exists, the receiver is released and the existing proxy is retained and returned.

## Discussion

A remote proxy can’t be used until its connection’s peer has a local proxy representing `target` in the other application.

This is the designated initializer for remote proxies. It returns an initialized object, which might be different than the original 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)