---
title: "decode(_:forKey:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/keyeddecodingcontainerprotocol/decode(_:forkey:)-5jtvg"
---

# decode(_:forKey:)

Decodes a value of the given type for the given key.

## Declaration

```swift
func decode(_ type: Int32.Type, forKey key: Self.Key) throws -> Int32
```

## Parameters

- `type`: The type of value to decode.
- `key`: The key that the decoded value is associated with.

## Return Value

Return Value A value of the requested type, if present for the given key and convertible to the requested type.

## Discussion

Discussion note: DecodingError.typeMismatch if the encountered encoded value is not convertible to the requested type. note: DecodingError.keyNotFound if self does not have an entry for the given key. note: DecodingError.valueNotFound if self has a null entry for the given key.
