<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 1.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "ExtensionFoundation",
  "identifier" : "/documentation/ExtensionFoundation/ConnectionHandler",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "ExtensionFoundation"
    ],
    "preciseIdentifier" : "s:19ExtensionFoundation17ConnectionHandlerV"
  },
  "title" : "ConnectionHandler"
}
-->

# ConnectionHandler

A type that contains a custom closure that handles incoming XPC connections.

```
@MainActor @preconcurrency struct ConnectionHandler
```

## Overview

This type manages a closure in your app extension that accepts incoming XPC connections from
a host app. Create an instance of this structure and initialize it with a closure for the
type of XPC connection the host app uses with app extensions. Assign the instance you created
to the [`configuration`](/documentation/ExtensionFoundation/AppExtension/configuration-swift.property) property of your custom [`AppExtension`](/documentation/ExtensionFoundation/AppExtension) type. When
the host app tries to open a connection, the system runs your closure to accept that connection.

Use this type to establish connections with either the <doc://com.apple.documentation/documentation/Foundation>
or <doc://com.apple.documentation/documentation/XPC> framework.

## Topics

### Initializing the connection handler

[`init(onConnection: (NSXPCConnection) -> Bool)`](/documentation/ExtensionFoundation/ConnectionHandler/init(onConnection:))

Initializes the connection handler with a closure that accepts a Foundation XPC object.

[`init(onSessionRequest: (XPCListener.IncomingSessionRequest) -> XPCListener.IncomingSessionRequest.Decision)`](/documentation/ExtensionFoundation/ConnectionHandler/init(onSessionRequest:))

Initializes the connection handler with a closure that accepts an XPC session.

## Relationships

### Conforms To

[`AppExtensionConfiguration`](/documentation/ExtensionFoundation/AppExtensionConfiguration)

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

---

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)