Created
September 15, 2018 22:24
-
-
Save azamsharp/29d26b4159a3186a376462092da8dde9 to your computer and use it in GitHub Desktop.
Category Structure
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
struct Category :Decodable { | |
let categoryName :String | |
let detail :[Detail] | |
struct Detail :Decodable { | |
let category :String | |
let trailerPrice :String | |
let isWatchlist :Bool? | |
} | |
private struct CodingKeys :CodingKey { | |
var stringValue :String | |
var intValue :Int? { | |
return nil | |
} | |
init?(stringValue :String) { | |
self.stringValue = stringValue | |
} | |
init?(intValue :Int) { | |
return nil | |
} | |
static let categoryName = CodingKeys(stringValue: "categoryName")! | |
} | |
init(from decoder :Decoder) throws { | |
let container = try decoder.container(keyedBy: CodingKeys.self) | |
self.categoryName = try container.decode(String.self, forKey: .categoryName) | |
let key = CodingKeys(stringValue: self.categoryName)! | |
self.detail = try container.decode([Detail].self, forKey: key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment