Skip to content

Instantly share code, notes, and snippets.

@Pasanpr Pasanpr/Song.swift Secret
Created Apr 5, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.