---
title: "initWithTarget:connection:"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdistantobject/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.

## Declaration

```occ
- (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 doc://com.apple.foundation/documentation/Foundation/NSConnection/connectionWithRegisteredName:host: class method.

## Return Value

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

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.

## See Also

### Creating a Remote Proxy

- [proxyWithTarget:connection:](foundation/nsdistantobject/proxywithtarget:connection:.md)
