---
title: "xpc_main(_:)"
framework: xpc
role: symbol
role_heading: Function
path: "xpc/xpc_main(_:)"
---

# xpc_main(_:)

Starts listening for incoming connections and processes them with the specified event handler.

## Declaration

```swift
func xpc_main(_ handler: xpc_connection_handler_t) -> Never
```

## Parameters

- `handler`: The handler to accept new connections with.

## Discussion

Discussion This is the springboard into the XPC service runtime. This function sets up your service bundle’s listener connection and manages it automatically. After this initial setup, this function calls dispatchMain(). You may override this behavior by setting the RunLoopType key in your XPC service bundle’s Info.plist under the XPCService dictionary.

## See Also

### Life cycle

- [xpc_connection_activate(_:)](xpc/xpc_connection_activate(_:).md)
- [xpc_connection_suspend(_:)](xpc/xpc_connection_suspend(_:).md)
- [xpc_connection_resume(_:)](xpc/xpc_connection_resume(_:).md)
- [xpc_connection_cancel(_:)](xpc/xpc_connection_cancel(_:).md)
- [xpc_transaction_begin()](xpc/xpc_transaction_begin().md)
- [xpc_transaction_end()](xpc/xpc_transaction_end().md)
- [xpc_connection_copy_invalidation_reason(_:)](xpc/xpc_connection_copy_invalidation_reason(_:).md)
