forked from FohoDuo/FoHo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipeSearchModel.swift
More file actions
executable file
·63 lines (54 loc) · 1.58 KB
/
RecipeSearchModel.swift
File metadata and controls
executable file
·63 lines (54 loc) · 1.58 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// RecipeSearchModel.swift
// FoHo
//
// Created by Scott Williams on 4/12/17.
// Copyright © 2017 FohoDuo. All rights reserved.
//
import UIKit
//Object for holding idividual search results for display in a list view
class RecipeSearchModel: NSObject {
//dictionary of objects obtained from JSON
let recipe: AnyObject
//constructor
init(recipe: AnyObject) {
self.recipe = recipe
super.init()
}
//gets the recipe name from the dictionary
func recipeName() -> String? {
if let name = recipe["recipeName"] {
return name as? String
}
return nil
}
//returns the id key for the recipe
func recipeID() -> String? {
if let id = recipe["id"] {
return id as? String
}
return nil
}
//returns the rating given by yummily
func rating() -> Int? {
if let rating = recipe["rating"] {
return rating as? Int
}
return nil
}
//gets the recipe image
func recipeImage() -> UIImage? {
if let urls = (recipe["smallImageUrls"] as! NSArray) as Array? {
let uriString = urls[0]
let uri = uriString as! String
//return uri
if let url = URL(string: uri),
let data = try? Data(contentsOf: url),
let image = UIImage(data: data) {
image.stretchableImage(withLeftCapWidth: 186, topCapHeight: 155)
return image
}
}
return UIImage(contentsOfFile: "forkknife")
}
}