diff options
author | Nicholas Tay <nick@windblume.net> | 2022-03-16 13:24:40 +1100 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-03-16 15:08:30 +1100 |
commit | 2096a23d43d271d42b2400c7cca8af5ba8b133c7 (patch) | |
tree | 57848806dd635e51009eceea936264ae272bc9fa /foray | |
parent | a296cb07500b1300385dae413149494eeb6d5905 (diff) | |
download | forayios-2096a23d43d271d42b2400c7cca8af5ba8b133c7.tar.gz forayios-2096a23d43d271d42b2400c7cca8af5ba8b133c7.tar.bz2 forayios-2096a23d43d271d42b2400c7cca8af5ba8b133c7.zip |
MyItem -> PenguinItem
Makes it clear which parts are tightly coupled. I want to learn how to
make this more generic so I can try hooking into other APIs easily
(which make require different destructuring of JSON).
Diffstat (limited to 'foray')
-rw-r--r-- | foray/ForayDetailViewController.swift | 2 | ||||
-rw-r--r-- | foray/ForayTableViewController.swift | 26 |
2 files changed, 14 insertions, 14 deletions
diff --git a/foray/ForayDetailViewController.swift b/foray/ForayDetailViewController.swift index 9c261ac..eb5b577 100644 --- a/foray/ForayDetailViewController.swift +++ b/foray/ForayDetailViewController.swift @@ -9,7 +9,7 @@ import UIKit class ForayDetailViewController: UIViewController { - var selectedItem: MyItem! + var selectedItem: PenguinItem! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var imageView: UIImageView! diff --git a/foray/ForayTableViewController.swift b/foray/ForayTableViewController.swift index 0643051..c984634 100644 --- a/foray/ForayTableViewController.swift +++ b/foray/ForayTableViewController.swift @@ -12,7 +12,7 @@ enum ItemType: String, Decodable { case quest } -struct MyItem: Decodable { +struct PenguinItem: Decodable { var type: ItemType var releaseDate: Date var id: String @@ -21,7 +21,7 @@ struct MyItem: Decodable { struct YearSection { var year: Date - var items: [MyItem] + var items: [PenguinItem] } class ForayTableViewCell: UITableViewCell { @@ -47,7 +47,7 @@ class ForayTableViewController: UITableViewController { // MARK: - Static data TEMP - var items = [MyItem]() + var items = [PenguinItem]() var sections = [YearSection]() // MARK: - On load @@ -95,16 +95,16 @@ class ForayTableViewController: UITableViewController { }) } - func loadApiData(onComplete: @escaping ([MyItem]) -> ()) { + func loadApiData(onComplete: @escaping ([PenguinItem]) -> ()) { // return [ -// MyItem(type: .item, releaseDate: parseDate("2006-05-26"), id: "mh", name: "Miners Helmet"), -// MyItem(type: .item, releaseDate: parseDate("2010-05-01"), id: "it", name: "Inner Tube"), -// MyItem(type: .item, releaseDate: parseDate("2009-04-24"), id: "tbg", name: "Toboggan"), -// MyItem(type: .item, releaseDate: parseDate("2006-03-29"), id: "spy", name: "Spy Phone"), -// MyItem(type: .item, releaseDate: parseDate("2008-11-18"), id: "bnb", name: "Black Ninja Belt"), -// MyItem(type: .quest, releaseDate: parseDate("2006-05-23"), id: "cmp", name: "Case of the Missing Puffles"), -// MyItem(type: .quest, releaseDate: parseDate("2009-11-16"), id: "gsm", name: "G's Secret Mission"), -// MyItem(type: .quest, releaseDate: parseDate("2009-04-18"), id: "cmc", name: "Case of the Missing Coins"), +// PenguinItem(type: .item, releaseDate: parseDate("2006-05-26"), id: "mh", name: "Miners Helmet"), +// PenguinItem(type: .item, releaseDate: parseDate("2010-05-01"), id: "it", name: "Inner Tube"), +// PenguinItem(type: .item, releaseDate: parseDate("2009-04-24"), id: "tbg", name: "Toboggan"), +// PenguinItem(type: .item, releaseDate: parseDate("2006-03-29"), id: "spy", name: "Spy Phone"), +// PenguinItem(type: .item, releaseDate: parseDate("2008-11-18"), id: "bnb", name: "Black Ninja Belt"), +// PenguinItem(type: .quest, releaseDate: parseDate("2006-05-23"), id: "cmp", name: "Case of the Missing Puffles"), +// PenguinItem(type: .quest, releaseDate: parseDate("2009-11-16"), id: "gsm", name: "G's Secret Mission"), +// PenguinItem(type: .quest, releaseDate: parseDate("2009-04-18"), id: "cmc", name: "Case of the Missing Coins"), // ] var request = URLRequest(url: URL(string: "https://.../dummy.json")!) @@ -122,7 +122,7 @@ class ForayTableViewController: UITableViewController { let dateStr = try container.decode(String.self) return parseDate(dateStr) }) - let items = try! jsonDecoder.decode([MyItem].self, from: data!) + let items = try! jsonDecoder.decode([PenguinItem].self, from: data!) print("json decoded") // Passing back to UI, need to do it on the main thread (I think due to async?) |