Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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