One Logo Pool Ball
Foundation · IOS API REFERENCE

CodableConfiguration

struct · iOS 15.0+ · SDK 27.1

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

A property wrapper that makes a type codable, by supplying a configuration that provides additional information for serialization. ``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`` and ``DecodingConfigurationProviding`` — to supply this data. Limiting the ``CodableConfiguration`` to statically-defined information protects clients from loading unexpected data, similar to the protection provided by ``NSSecureCoding``. In the following example, the `Message` type uses `@CodableConfiguration` for an ``AttributedString`` property called `content`. While ``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`` for the custom `MyAttributes` type, `Message` uses ``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() } ```

Members (0)

This type has no directly callable members in this snapshot. See the framework’s skipped declarations for unsupported APIs.

Skipped declarations

4 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

CodableConfiguration.init(wrappedValue:from:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

CodableConfiguration.wrappedValue

This declaration needs Swift generic type arguments. (no canonical witness for T)

CodableConfiguration.init(wrappedValue:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

CodableConfiguration.init(wrappedValue:from:)

This declaration needs Swift generic type arguments. (no canonical witness for T)

All Foundation types →