forked from tvidenov/appstore-clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppCategory.swift
71 lines (49 loc) · 1.73 KB
/
AppCategory.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
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
64
65
66
67
68
//
// Models.swift
// AppStore
//
// Created by Tihomir Videnov on 11/6/16.
// Copyright © 2016 Tihomir Videnov. All rights reserved.
//
import UIKit
class AppCategory: NSObject {
var name: String?
var apps: [App]?
var type: String?
override func setValue(_ value: Any?, forKey key: String) {
if key == "apps" {
apps = [App]()
for dict in value as! [[String:Any]] {
let app = App()
app.setValuesForKeys(dict)
apps?.append(app)
}
} else {
super.setValue(value, forKey: key)
}
}
//for offline testing
static func sampleAppCategories() -> [AppCategory] {
let bestNewAppsCategory = AppCategory()
bestNewAppsCategory.name = "Best New Apps"
var apps = [App]()
let frozenApp = App()
frozenApp.name = "Disney Build It: Frozen"
frozenApp.imageName = "frozen"
frozenApp.category = "Entertaiment"
frozenApp.price = NSNumber(value: 3.99)
apps.append(frozenApp)
bestNewAppsCategory.apps = apps
let bestNewGamesCategory = AppCategory()
bestNewGamesCategory.name = "Best New Games"
var bestNewGamesApps = [App]()
var telepaintApp = App()
telepaintApp.name = "Telepaint"
telepaintApp.category = "Games"
telepaintApp.imageName = "telepaint"
telepaintApp.price = NSNumber(value: 1.99)
bestNewGamesApps.append(telepaintApp)
bestNewGamesCategory.apps = bestNewGamesApps
return [bestNewAppsCategory, bestNewGamesCategory]
}
}