Skip to content

Instantly share code, notes, and snippets.

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

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[] as? Int,
let nameValue = json[] 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
} = idValue = 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.