<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/CodableConfiguration",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation20CodableConfigurationV"
  },
  "title" : "CodableConfiguration"
}
-->

# CodableConfiguration

A property wrapper that makes a type codable, by supplying a configuration that provides additional information for serialization.

```
@propertyWrapper struct CodableConfiguration<T, ConfigurationProvider> where T : DecodableWithConfiguration, T : EncodableWithConfiguration, ConfigurationProvider : DecodingConfigurationProviding, ConfigurationProvider : EncodingConfigurationProviding, T.DecodingConfiguration == ConfigurationProvider.DecodingConfiguration, T.EncodingConfiguration == ConfigurationProvider.EncodingConfiguration
```

## Overview

[`CodableConfiguration`](/documentation/Foundation/CodableConfiguration) allows you to create <doc://com.apple.documentation/documentation/Swift/Codable> types whose members don’t all conform to <doc://com.apple.documentation/documentation/Swift/Codable>. For types that can’t support encoding and decoding by themselves but could become encodable and decodable with some statically-defined information, use the `@CodableConfiguration` wrapper. This lets you assign a configuration provider — a type that conforms to both [`EncodingConfigurationProviding`](/documentation/Foundation/EncodingConfigurationProviding) and [`DecodingConfigurationProviding`](/documentation/Foundation/DecodingConfigurationProviding) — to supply this data.

Limiting the [`CodableConfiguration`](/documentation/Foundation/CodableConfiguration) to statically-defined information protects clients from loading unexpected data, similar to the protection provided by [`NSSecureCoding`](/documentation/Foundation/NSSecureCoding).

In the following example, the `Message` type uses `@CodableConfiguration` for an [`AttributedString`](/documentation/Foundation/AttributedString) property called `content`. While [`AttributedString`](/documentation/Foundation/AttributedString) does conform to <doc://com.apple.documentation/documentation/Swift/Codable>, it can only encode its known attributes — those declared by the platform SDK — as part of this conformance. By adding a [`CodableConfiguration`](/documentation/Foundation/CodableConfiguration) for the custom `MyAttributes` type, `Message` uses [`encode(to:configuration:)`](/documentation/Foundation/EncodableWithConfiguration/encode(to:configuration:)) when encoding `content`, which preserves the custom attributes.

```swift
struct Message: Codable {
    let date: Date
    let sender: Person
    @CodableConfiguration(from: MyAttributes.self) var content = AttributedString()
}
```

## Topics

### Creating a Codable Configuration

[`init(wrappedValue:)`](/documentation/Foundation/CodableConfiguration/init(wrappedValue:))

Creates a codable configuration wrapper for the given value.

[`init(wrappedValue:from:)`](/documentation/Foundation/CodableConfiguration/init(wrappedValue:from:)-46oo6)

Creates a codable configuration wrapper for the given value, using the given configuration provider type.

[`init(wrappedValue:from:)`](/documentation/Foundation/CodableConfiguration/init(wrappedValue:from:)-8mkxk)

Creates a codable configuration wrapper for the given value, using given configuration provider type identified by key path.

### Accessing the Wrapped Value

[`wrappedValue`](/documentation/Foundation/CodableConfiguration/wrappedValue)

The underlying value to make codable, using data from the configuration provider.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Sendable`](/documentation/Swift/Sendable)

[`Decodable`](/documentation/Swift/Decodable)

[`Equatable`](/documentation/Swift/Equatable)

[`Hashable`](/documentation/Swift/Hashable)

[`Encodable`](/documentation/Swift/Encodable)

---

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)