Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active December 22, 2019 04:39
Show Gist options
  • Save hlung/20a1e13c4e9ee8454cbbf39cc401aa26 to your computer and use it in GitHub Desktop.
Save hlung/20a1e13c4e9ee8454cbbf39cc401aa26 to your computer and use it in GitHub Desktop.
let exampleData = """
[
{
"type": "cat",
"name": "Kitty",
},
{
"type": "dog",
"name": "Doggy",
}
]
""".data(using: .utf8)!
protocol Animal: CustomDebugStringConvertible {
var name: String { get }
var debugDescription: String { get }
}
extension Animal {
var debugDescription: String {
return "\(type(of: self)) name: \(name)"
}
}
struct Cat: Animal, Decodable {
let name: String
func purr() {
// purr
}
}
struct Dog: Animal, Decodable {
let name: String
func bark() {
// bark
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment