-
-
Save Pasanpr/659f04904bfffb5143762fb0161cf28b to your computer and use it in GitHub Desktop.
This file contains 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
extension Song { | |
init?(json: [String: Any]) { | |
struct Key { | |
static let id = "trackId" | |
static let name = "trackName" | |
static let censoredName = "trackCensoredName" | |
static let trackTime = "trackTimeMillis" | |
static let isExplicit = "trackExplicitness" | |
} | |
guard let idValue = json[Key.id] as? Int, | |
let nameValue = json[Key.name] as? String, | |
let censoredNameValue = json[Key.censoredName] as? String, | |
let trackTimeValue = json[Key.trackTime] as? Int, | |
let isExplicitString = json[Key.isExplicit] as? String else { | |
return nil | |
} | |
self.id = idValue | |
self.name = nameValue | |
self.censoredName = censoredNameValue | |
self.trackTime = trackTimeValue | |
self.isExplicit = isExplicitString == "notExplicit" ? false : true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment