Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
Last active January 13, 2019 11:29
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 mwaterfall/1fa6e41d4e00f7a9620bec0abe083f5b to your computer and use it in GitHub Desktop.
Save mwaterfall/1fa6e41d4e00f7a9620bec0abe083f5b to your computer and use it in GitHub Desktop.
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