Skip to content

Instantly share code, notes, and snippets.

@marslin1220
Created January 10, 2019 16:54
Show Gist options
  • Save marslin1220/2614c5ceae8049bf144dc059a03686d5 to your computer and use it in GitHub Desktop.
Save marslin1220/2614c5ceae8049bf144dc059a03686d5 to your computer and use it in GitHub Desktop.
public class DramaInfo: NSObject, Codable {
@objc public let currentEpisode: Int
@objc public let episodeID: String
@objc public let name: String
@objc public let viewCount: Int
@objc public let totalEpisode: Int
enum CodingKeys: String, CodingKey {
case currentEpisode = "currentEps"
case episodeID = "id"
case name = "name"
case viewCount = "views"
case totalEpisode = "totalEps"
}
public required init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
currentEpisode = try values.decode(Int.self, forKey: .currentEpisode)
let episodeIDInt = try values.decode(Int.self, forKey: .episodeID)
episodeID = String(episodeIDInt)
name = try values.decode(String.self, forKey: .name)
viewCount = try values.decode(Int.self, forKey: .viewCount)
totalEpisode = try values.decode(Int.self, forKey: .totalEpisode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment