---
title: "init(xpcService:targetQueue:options:requirement:cancellationHandler:)"
framework: xpc
role: symbol
role_heading: Initializer
path: "xpc/xpcsession/init(xpcservice:targetqueue:options:requirement:cancellationhandler:)"
---

# init(xpcService:targetQueue:options:requirement:cancellationHandler:)

Creates a new session object representing a connection to the named service, and requires that the session peer has the specified requirement.

## Declaration

```swift
@preconcurrency convenience init(xpcService: String, targetQueue: DispatchQueue? = nil, options: XPCSession.InitializationOptions = .none, requirement: XPCPeerRequirement, cancellationHandler: (@Sendable (XPCRichError) -> Void)? = nil) throws
```

## Discussion

Discussion requirement: The requirement the peer must have note: All messages received on this session will be checked to ensure that they come from a peer who satisfies the requirement. When a reply is expected on the session and the peer does not satisfy the requirement, the session will be canceled and user’s cancelation handler will be invoked with XPCRichError describing the code signing error.
