Last active
January 13, 2019 11:29
-
-
Save mwaterfall/1fa6e41d4e00f7a9620bec0abe083f5b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Material: String { | |
case wood, metal, glass, other | |
} | |
extension Material: Codable {} | |
extension Material: UnknownCaseRepresentable { | |
static let unknownCase: Material = .other | |
} | |
Material(rawValue: "glass") | |
// glass | |
Material(rawValue: "stone") | |
// other | |
let json = """ | |
["glass", "stone"] | |
""" | |
try? JSONDecoder().decode([Material].self, from: json.data(using: .utf8)!) | |
// [glass, other] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment