---
title: "nestedContainer(keyedBy:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/unkeyedencodingcontainer/nestedcontainer(keyedby:)"
---

# nestedContainer(keyedBy:)

Encodes a nested container keyed by the given type and returns it.

## Declaration

```swift
mutating func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type) -> KeyedEncodingContainer<NestedKey> where NestedKey : CodingKey
```

## Parameters

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

## Return Value

Return Value A new keyed encoding container.
