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

# xpc_connection_create(_:_:)

Creates a new connection object.

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

## Parameters

`name`

If non-`NULL`, the name of the service with which to connect. The returned connection will be a peer.

    If     `NULL`    , an anonymous listener connection will be created. You can embed the ability to create new peer connections in an endpoint, which can be inserted into a message and sent to another process .

`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(_:_:)).

## Return Value

A new connection object. The caller is responsible for disposing of the returned object with [`xpc_release`](/documentation/XPC/xpc_release) when it is no longer needed.

## Discussion

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

XPC connections, like dispatch sources, are returned in a suspended state, so you must call [`xpc_connection_resume(_:)`](/documentation/XPC/xpc_connection_resume(_:)) in order to begin receiving events from the connection. Also like dispatch sources, connections must be resumed in order to be safely released. It is a programming error to release a suspended connection.

---

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)