<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.8.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSXPCConnection",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSXPCConnection"
  },
  "title" : "NSXPCConnection"
}
-->

# NSXPCConnection

A bidirectional communication channel between two processes.

```
class NSXPCConnection
```

## Overview

This class is the primary means of creating and configuring the communication mechanism between two processes. Each process has one instance of this class to represent the endpoint in the communication channel.

## Topics

### Creating a connection

[`init(listenerEndpoint:)`](/documentation/Foundation/NSXPCConnection/init(listenerEndpoint:))

Initializes an [`NSXPCConnection`](/documentation/Foundation/NSXPCConnection) object to connect to an [`NSXPCListener`](/documentation/Foundation/NSXPCListener) object in another process, identified by an [`NSXPCListenerEndpoint`](/documentation/Foundation/NSXPCListenerEndpoint) object.

[`init(machServiceName:options:)`](/documentation/Foundation/NSXPCConnection/init(machServiceName:options:))

Initializes an [`NSXPCConnection`](/documentation/Foundation/NSXPCConnection) object to connect to a LaunchAgent or LaunchDaemon with a name advertised in a `launchd.plist`.

[`NSXPCConnection.Options`](/documentation/Foundation/NSXPCConnection/Options)

Options that you can pass to a connection.

[`init(serviceName:)`](/documentation/Foundation/NSXPCConnection/init(serviceName:))

Initializes an [`NSXPCConnection`](/documentation/Foundation/NSXPCConnection) object to connect to an [`NSXPCListener`](/documentation/Foundation/NSXPCListener) object in an XPC service, identified by a service name.

### Managing connection state

[`activate()`](/documentation/Foundation/NSXPCConnection/activate())

Activates the connection.

[`resume()`](/documentation/Foundation/NSXPCConnection/resume())

Starts or resumes handling of messages on a connection.

[`invalidate()`](/documentation/Foundation/NSXPCConnection/invalidate())

Invalidates the connection.

[`suspend()`](/documentation/Foundation/NSXPCConnection/suspend())

Suspends the connection.

[`interruptionHandler`](/documentation/Foundation/NSXPCConnection/interruptionHandler)

An interruption handler that is called if the remote process exits or crashes.

[`invalidationHandler`](/documentation/Foundation/NSXPCConnection/invalidationHandler)

An invalidation handler that is called if the connection can not be formed or the connection has terminated and may not be re-established.

[`current()`](/documentation/Foundation/NSXPCConnection/current())

Returns the current connection, in the context of a call to a method on your exported object.

[`scheduleSendBarrierBlock(_:)`](/documentation/Foundation/NSXPCConnection/scheduleSendBarrierBlock(_:))

Add a barrier block to execute on the connection.

### Managing the connection interface

[`serviceName`](/documentation/Foundation/NSXPCConnection/serviceName)

The name of the XPC service that this connection was configured to connect to.

[`endpoint`](/documentation/Foundation/NSXPCConnection/endpoint)

If the connection was created with an [`NSXPCListenerEndpoint`](/documentation/Foundation/NSXPCListenerEndpoint) object, returns the endpoint object used.

[`exportedInterface`](/documentation/Foundation/NSXPCConnection/exportedInterface)

The [`NSXPCInterface`](/documentation/Foundation/NSXPCInterface) object that describes the protocol for the exported object on this connection.

[`exportedObject`](/documentation/Foundation/NSXPCConnection/exportedObject)

An exported object for the connection.

[`remoteObjectInterface`](/documentation/Foundation/NSXPCConnection/remoteObjectInterface)

Defines the [`NSXPCInterface`](/documentation/Foundation/NSXPCInterface) object that describes the protocol for the object represented by the `remoteObjectProxy`.

[`remoteObjectProxy`](/documentation/Foundation/NSXPCConnection/remoteObjectProxy)

Returns a proxy for the remote object (that is, the `exportedObject` from the other side of this connection).

### Working with security attributes

[`auditSessionIdentifier`](/documentation/Foundation/NSXPCConnection/auditSessionIdentifier)

The BSM audit session identifier for the connecting process.

[`processIdentifier`](/documentation/Foundation/NSXPCConnection/processIdentifier)

The process ID (PID) of the connecting process.

[`effectiveGroupIdentifier`](/documentation/Foundation/NSXPCConnection/effectiveGroupIdentifier)

The effective group ID (EGID) of the connecting process.

[`effectiveUserIdentifier`](/documentation/Foundation/NSXPCConnection/effectiveUserIdentifier)

The effective user ID (EUID) of the connecting process.

### Working with proxy objects

[`remoteObjectProxyWithErrorHandler(_:)`](/documentation/Foundation/NSXPCConnection/remoteObjectProxyWithErrorHandler(_:))

Returns a proxy for the remote object (that is, the object exported from the other side of this connection) with the specified error handler.

[`synchronousRemoteObjectProxyWithErrorHandler(_:)`](/documentation/Foundation/NSXPCConnection/synchronousRemoteObjectProxyWithErrorHandler(_:))

Returns a proxy that makes a synchronous IPC call instead of the default async behavior.

### Working with code signing

[`setCodeSigningRequirement(_:)`](/documentation/Foundation/NSXPCConnection/setCodeSigningRequirement(_:))

Sets the code signing requirement for this connection.

### Error codes

[`NSXPCConnectionInterrupted`](/documentation/Foundation/NSXPCConnectionInterrupted-swift.var)

The XPC connection was interrupted.

[`NSXPCConnectionInvalid`](/documentation/Foundation/NSXPCConnectionInvalid-swift.var)

The XPC connection was invalid.

[`NSXPCConnectionReplyInvalid`](/documentation/Foundation/NSXPCConnectionReplyInvalid-swift.var)

The XPC connection reply was invalid.

[`NSXPCConnectionErrorMinimum`](/documentation/Foundation/NSXPCConnectionErrorMinimum-swift.var)

The lower bounds of XPC connection error code values.

[`NSXPCConnectionErrorMaximum`](/documentation/Foundation/NSXPCConnectionErrorMaximum-swift.var)

The upper bounds of XPC connection error code values.

[`NSXPCConnectionCodeSigningRequirementFailure`](/documentation/Foundation/NSXPCConnectionCodeSigningRequirementFailure-swift.var)

A code-signing requirement check failed.

[`NSXPCConnectionInterrupted`](/documentation/Foundation/NSXPCConnectionInterrupted-c.enum.case)

The XPC connection was interrupted.

[`NSXPCConnectionInvalid`](/documentation/Foundation/NSXPCConnectionInvalid-c.enum.case)

The XPC connection was invalid.

[`NSXPCConnectionReplyInvalid`](/documentation/Foundation/NSXPCConnectionReplyInvalid-c.enum.case)

The XPC connection reply was invalid.

[`NSXPCConnectionErrorMinimum`](/documentation/Foundation/NSXPCConnectionErrorMinimum-c.enum.case)

The lower bounds of XPC connection error code values.

[`NSXPCConnectionErrorMaximum`](/documentation/Foundation/NSXPCConnectionErrorMaximum-c.enum.case)

The upper bounds of XPC connection error code values.

[`NSXPCConnectionCodeSigningRequirementFailure`](/documentation/Foundation/NSXPCConnectionCodeSigningRequirementFailure-c.enum.case)

A code-signing requirement check failed.



---

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)