Skip to content

Instantly share code, notes, and snippets.

@randomguy0815
Created March 27, 2019 09:38
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/5d84e73c8a972dca13e9116f8577d10d to your computer and use it in GitHub Desktop.
Save randomguy0815/5d84e73c8a972dca13e9116f8577d10d to your computer and use it in GitHub Desktop.
struct EnumModelIfPresent: Decodable {
   
enum Keys: CodingKey {
case status
}
   
enum Status: String, Decodable {
case enabled
case disabled
}
   
let status: Status?
   
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Keys.self)
   
self.status = try container.decodeIfPresent(Status.self, forKey: .status)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment