---
title: "container(keyedBy:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/decoder/container(keyedby:)"
---

# container(keyedBy:)

Returns the data stored in this decoder as represented in a container keyed by the given key type.

## Declaration

```swift
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey
```

## Parameters

- `type`: The key type to use for the container.

## Return Value

Return Value A keyed decoding container view into this decoder.

## Discussion

Discussion note: DecodingError.typeMismatch if the encountered stored value is not a keyed container.
