Created
April 5, 2021 10:35
-
-
Save donnywals/23f5601f4f7b1bd04c3600ff423f3afc 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
enum Status: Decodable { | |
case completed, inProgress | |
case other(String) | |
init(from decoder: Decoder) throws { | |
let container = try decoder.singleValueContainer() | |
let value = try container.decode(String.self) | |
switch value { | |
case "completed": self = .completed | |
case "inProgress": self = .inProgress | |
default: self = .other(value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment