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

# container(keyedBy:)

Returns an encoding container appropriate for holding multiple values keyed by the given key type.

## Declaration

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

## Parameters

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

## Return Value

Return Value A new keyed encoding container.

## Discussion

Discussion You must use only one kind of top-level encoding container. This method must not be called after a call to unkeyedContainer() or after encoding a value through a call to singleValueContainer()
