-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnime.swift
38 lines (34 loc) · 951 Bytes
/
Anime.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// Anime.swift
// Anibuddy
//
// Created by Kyle Grande.
//
import Foundation
import CoreData
extension Anime {
static func createFromJSON(_ json: [String: Any], context: NSManagedObjectContext) -> Anime? {
guard let mal_id = json["mal_id"] as? Int64,
let title = json["title_english"] as? String,
let images = json["images"] as? [String: Any],
let jpgImages = images["jpg"] as? [String: Any],
let imageUrl = jpgImages["large_image_url"] as? String,
let synopsis = json["synopsis"] as? String,
let type = json["type"] as? String,
let episodes = json["episodes"] as? Int64,
let score = json["score"] as? Double
else {
return nil
}
let anime = Anime(context: context)
anime.mal_id = mal_id
anime.title = title
anime.imageUrl = imageUrl
anime.synopsis = synopsis
anime.type = type
anime.episodes = episodes
anime.score = score
anime.isFavorite = false
return anime
}
}