<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/XPCReceivedMessage/decode(as:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "s:3XPC18XPCReceivedMessageV6decode2asxxm_tKSeRzlF"
  },
  "title" : "decode(as:)"
}
-->

# decode(as:)

Decodes a message as the given type.

```
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

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

## Discussion

If the message data doesn’t decode to the type, this method throws the appropriate <doc://com.apple.documentation/documentation/Swift/DecodingError>.

---

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)