Last active
December 22, 2019 04:39
-
-
Save hlung/20a1e13c4e9ee8454cbbf39cc401aa26 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
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