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

# xpc_connection_create_mach_service(_:_:_:)

Creates a new connection object that represents a Mach service.

```
func xpc_connection_create_mach_service(_ name: UnsafePointer<CChar>, _ targetq: dispatch_queue_t?, _ flags: UInt64) -> xpc_connection_t
```

## Parameters

`name`

The name of the remote service with which to connect. The service name must exist in a Mach bootstrap that is accessible to the process and be advertised in a `launchd.plist`.

`targetq`

The GCD queue to which the event handler block will be submitted. This parameter may be `NULL`, in which case the connection’s target queue will be the default target queue of `libdispatch`, defined as `DISPATCH_TARGET_QUEUE_DEFAULT`. The target queue may be changed later with a call to [`xpc_connection_set_target_queue(_:_:)`](/documentation/XPC/xpc_connection_set_target_queue(_:_:)).

`flags`

Additional attributes with which to create the connection.

## Return Value

A new connection object.

## Discussion

If the [`XPC_CONNECTION_MACH_SERVICE_LISTENER`](/documentation/XPC/XPC_CONNECTION_MACH_SERVICE_LISTENER) flag is given to this method, then the connection returned will be a listener connection. Otherwise, a peer connection will be returned. See the documentation for [`xpc_connection_set_event_handler(_:_:)`](/documentation/XPC/xpc_connection_set_event_handler(_:_:)) for the semantics of listener connections versus peer connections.

This method will succeed even if the named service does not exist. This is because the Mach namespace is not queried for the service name until the first call to [`xpc_connection_resume(_:)`](/documentation/XPC/xpc_connection_resume(_:)).

---

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)