---
title: "decode(as:)"
framework: xpc
role: symbol
role_heading: Instance Method
path: "xpc/xpcreceivedmessage/decode(as:)"
---

# decode(as:)

Decodes a message as the given type.

## Declaration

```swift
func decode<T>(as type: T.Type = T.self) throws -> T where T : Decodable
```

## Parameters

- `type`: The type of the value in the message.

## Return Value

Return Value A value of the specified type if the message data decodes successfully.

## Discussion

Discussion If the message data doesn’t decode to the type, this method throws the appropriate DecodingError.

## See Also

### Accessing message content

- [isSync](xpc/xpcreceivedmessage/issync.md)
