Created
March 27, 2019 09:38
-
-
Save randomguy0815/5d84e73c8a972dca13e9116f8577d10d 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
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