Created
January 13, 2019 11:23
-
-
Save mwaterfall/11f1646dd5c9a3102fdbc4f78e8d52bc to your computer and use it in GitHub Desktop.
This file contains 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
extension RawRepresentable where RawValue: Decodable { | |
init(from decoder: Decoder, default: Self) throws { | |
let container = try decoder.singleValueContainer() | |
let rawValue = try container.decode(RawValue.self) | |
self = Self(rawValue: rawValue) ?? `default` | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment