I have a parent class with several methods and attributes:
class Animal {
var var1: ...
var var2: ...
func func1() {}
func func2() {}
}
And Child class:
class Dog: Animal, Codable {
var name = ""
}
I need to add to parent class a method, that will return result of JSONEncoder().encode
for child class. Something like:
let dog = Dog()
dog.name = "Bob"
let jsonString = dog.jsonString() // {"name":"Bob"}
Can I do this?