---
title: ConnectionHandler
framework: extensionfoundation
role: symbol
role_heading: Structure
path: extensionfoundation/connectionhandler
---

# ConnectionHandler

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

## Declaration

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

## Mentioned in

Building an app extension to support a host app

## Overview

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 property of your custom 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 Foundation or XPC framework.

## Topics

### Initializing the connection handler

- [init(onConnection:)](extensionfoundation/connectionhandler/init(onconnection:).md)
- [init(onSessionRequest:)](extensionfoundation/connectionhandler/init(onsessionrequest:).md)

## Relationships

### Conforms To

- [AppExtensionConfiguration](extensionfoundation/appextensionconfiguration.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### App-extension setup

- [Building an app extension to support a host app](extensionfoundation/building-an-app-extension-to-support-a-host-app.md)
- [AppExtension](extensionfoundation/appextension.md)
- [AppExtensionConfiguration](extensionfoundation/appextensionconfiguration.md)
