<!--
{
  "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/CodableWithConfiguration",
  "metadataVersion" : "0.1.0",
  "role" : "Type Alias",
  "symbol" : {
    "kind" : "Type Alias",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation24CodableWithConfigurationa"
  },
  "title" : "CodableWithConfiguration"
}
-->

# CodableWithConfiguration

A type that can convert itself into and out of an external representation with the help of a configuration that handles encoding contained types.

```
typealias CodableWithConfiguration = DecodableWithConfiguration & EncodableWithConfiguration
```

## Discussion

[`CodableWithConfiguration`](/documentation/Foundation/CodableWithConfiguration) is a type alias for the [`EncodableWithConfiguration`](/documentation/Foundation/EncodableWithConfiguration) and [`DecodableWithConfiguration`](/documentation/Foundation/DecodableWithConfiguration) protocols. Use this protocol to support codability in a type that can’t conform to <doc://com.apple.documentation/documentation/Swift/Codable> by itself, but can do so with additional statically-defined configuration provided by a [`CodableConfiguration`](/documentation/Foundation/CodableConfiguration) instance.

[`AttributedString`](/documentation/Foundation/AttributedString) uses this approach to allow an instance to contain arbitrary attributes, including frameworks outside of Foundation or the platform SDK. It does this by including one or more [`AttributeScope`](/documentation/Foundation/AttributeScope) instances, a type that conforms to [`EncodingConfigurationProviding`](/documentation/Foundation/EncodingConfigurationProviding) and [`DecodingConfigurationProviding`](/documentation/Foundation/DecodingConfigurationProviding). An attribute scope like [`AttributeScopes.SwiftUIAttributes`](/documentation/Foundation/AttributeScopes/SwiftUIAttributes) defines attribute keys, and conforms to [`AttributeScope`](/documentation/Foundation/AttributeScope) to provide configuration instances that know the [`AttributedStringKey`](/documentation/Foundation/AttributedStringKey) types and their associated [`Value`](/documentation/Foundation/AttributedStringKey/Value) types. With this type information, an [`AttributedString`](/documentation/Foundation/AttributedString) can encode all of its attributes, even from frameworks other than Foundation.

---

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)