Created
March 23, 2024 17:35
-
-
Save lukluca/82484b40a8b48ee96e734529f3d0bdbb to your computer and use it in GitHub Desktop.
Swift DecodableConfiguration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@propertyWrapper struct DecodableConfiguration<T, ConfigurationProvider> : Decodable where T : DecodableWithConfiguration, ConfigurationProvider : DecodingConfigurationProviding, T.DecodingConfiguration == ConfigurationProvider.DecodingConfiguration { | |
var wrappedValue: T | |
init(wrappedValue: T) { | |
self.wrappedValue = wrappedValue | |
} | |
init(wrappedValue: T, from configurationProvider: ConfigurationProvider.Type) { | |
self.wrappedValue = wrappedValue | |
} | |
/// Creates a new instance by decoding from the given decoder. | |
/// | |
/// This initializer throws an error if reading from the decoder fails, or | |
/// if the data read is corrupted or otherwise invalid. | |
/// | |
/// - Parameter decoder: The decoder to read data from. | |
init(from decoder: any Decoder) throws { | |
self.wrappedValue = try T(from: decoder, configuration: ConfigurationProvider.decodingConfiguration) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment