-
-
Save Pasanpr/487e1d9044fde1313dc08a588db72482 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 Artist { | |
convenience init?(json: [String: Any]) { | |
struct Key { | |
static let artistName = "artistName" | |
static let artistId = "artistId" | |
static let primaryGenreId = "primaryGenreId" | |
} | |
guard let artistName = json[Key.artistName] as? String, | |
let artistId = json[Key.artistId] as? Int, | |
let primaryGenreId = json[Key.primaryGenreId] as? Int, | |
let primaryGenreValue = Genre(rawValue: primaryGenreId) else { | |
return nil | |
} | |
self.init(id: artistId, name: artistName, primaryGenre: primaryGenreValue, albums: []) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment