A type that represents a message sent between a session and a listener.
struct XPCReceivedMessage
Accessing message content
- decode(as:))
func decode<T>(as: T.Type) throws -> T— Decodes a message as the given type. - isSync
var isSync: Bool— A Boolean value that indicates if this message is from a synchronous request.
Replying to messages
- expectsReply
var expectsReply: Bool— A Boolean value that indicates if the client that sent the message expects a reply. - reply(_:))
func reply<Message>(Message)— Sends a reply to the originator of the message. - handoffReply(to:_:))
func handoffReply(to: DispatchQueue, () -> Void) -> (any Encodable)?— Informs the system when message processing and response continues in a separate dispatch queue.
Instance Methods
- senderSatisfies(_:))
func senderSatisfies(XPCPeerRequirement) -> Bool— Check whether the sender of the received message satisfies the specified requirement.
See Also
Interprocess communication
expectsReply
Instance Property | XPC
A Boolean value that indicates if the client that sent the message expects a reply.
var expectsReply: Bool { get }
See Also
Replying to messages
decode(as:)
Instance Method | XPC
Decodes a message as the given type.
func decode<T>(as type: T.Type = T.self) throws -> T where T : Decodable
A value of the specified type if the message data decodes successfully.
Parameters
- type: The type of the value in the message.
See Also
Accessing message content
handoffReply(to:_:)
Instance Method | XPC
Informs the system when message processing and response continues in a separate dispatch queue.
@preconcurrency func handoffReply(to queue: DispatchQueue, _ continuation: @escaping @Sendable () -> Void) -> (any Encodable)?
This method always returns nil, allowing a message handler closure to return a value.
Parameters
- queue: The dispatch queue where message processing continues. The queue must be an immutible queue hierarchy.
- continuation: The closure to perform on
queue.
See Also
Replying to messages
isSync
Instance Property | XPC
A Boolean value that indicates if this message is from a synchronous request.
var isSync: Bool { get }
See Also
Accessing message content
reply(_:)
Instance Method | XPC
Sends a reply to the originator of the message.
func reply<Message>(_ object: Message) where Message : Encodable
When a listener receives an XPCReceivedMessage, the message keeps track of the client that sent it. This function sends the specified reply message back to the originating client.
Don’t call this function more than once on a single message, and don’t call it on a message that wasn’t received from a client. Calling it more than once or sending a reply using a message that wasn’t received triggers an API misuse crash.
Parameters
- object: A message to send back to the client that sent the original message.
See Also
Replying to messages
senderSatisfies(_:)
Instance Method | XPC
Check whether the sender of the received message satisfies the specified requirement.
func senderSatisfies(_ requirement: XPCPeerRequirement) -> Bool
A Bool indicating whether the sender satisfies the requirement