Skip to content

Instantly share code, notes, and snippets.

@randomguy0815
Created March 27, 2019 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomguy0815/d108969879d096fccab3d13b05b71cd0 to your computer and use it in GitHub Desktop.
Save randomguy0815/d108969879d096fccab3d13b05b71cd0 to your computer and use it in GitHub Desktop.
struct EnumModelRawValue: Decodable {
   
enum Keys: CodingKey {
case status
}
   
enum Status: String {
case enabled
case disabled
   
case unsupported
}
   
let status: Status
   
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Keys.self)
   
let statusValue = try container.decode(String.self, forKey: .status)
self.status = Status(rawValue: statusValue) ?? .unsupported
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment