Skip to content

Instantly share code, notes, and snippets.

@donnywals
Created April 5, 2021 10:35
Show Gist options
  • Save donnywals/23f5601f4f7b1bd04c3600ff423f3afc to your computer and use it in GitHub Desktop.
Save donnywals/23f5601f4f7b1bd04c3600ff423f3afc to your computer and use it in GitHub Desktop.
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