Skip to content

Instantly share code, notes, and snippets.

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

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