bignerdranch / Freddy

A reusable framework for parsing JSON in Swift.
MIT License
1.09k stars 120 forks source link

Decoding not working #229

Closed Valentin-VK closed 7 years ago

Valentin-VK commented 7 years ago

Hello! This code it's not working Decoding. Please help.

public struct Video {
    var id: Int!
    var title: String!
}

extension Video:JSONDecodable {
    init(json: JSON) throws {
        self.id = try json.getInt(at: "id")
        self.title = try json.getString(at: "title")
    }
}

public struct VideoArtist {
    var artistId: Int!
    var video: Video!
}

extension VideoArtist:JSONDecodable {
    init(json: JSON) throws {
        self.artistId = try json.getInt(at: "id")
        self.video = try? json.decode(at: "video", type: Video.self)
    }
}
Error: In argument type 'Video.Type', 'Video' does not conform to expected type 'JSONDecodable'