<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: 5.0.0 -",
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_main(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_main"
  },
  "title" : "xpc_main(_:)"
}
-->

# xpc_main(_:)

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

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

## Parameters

`handler`

The handler to accept new connections with.

## 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 <doc://com.apple.documentation/documentation/Dispatch/dispatchMain()>. You may override this behavior by setting the <doc://com.apple.documentation/documentation/BundleResources/Information-Property-List/XPCService/RunLoopType> key in your XPC service bundle’s `Info.plist` under the `XPCService` dictionary.

---

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)