HandyJSON
HandyJSON copied to clipboard
struct can't have designated initializer.
For a struct, if it has any designated initializer, compiler will complaint that:
type does not conform to protocol 'HandyJSON'.
For example, this struct can't pass compiler:
struct Animal: HandyJSON {
var name: String?
var id: String?
var num: Int?
init(name: String?, id: String?, num: Int?) {
self.name = name
self.id = id
self.num = num
}
}
I'm not quite sure if this is a bug.
Any class/struct conform to protocol 'HandyJSON' need an empty initializer. Struct has a default one but when you declare other it'll be overrid, which make the struct do not conform to 'HandyJSON'.
On this situation, you do need to declare an empty one.
struct Animal: HandyJSON {
var name: String?
var id: String?
var num: Int?
init() {}
init(name: String?, id: String?, num: Int?) {
self.name = name
self.id = id
self.num = num
}
}
I'll specify it in the readme later.
That makes sense. And thanks for revising readme.