From bd7761216a065b0dd859cb19d709996739a240cd Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Sun, 17 Jul 2022 02:25:12 +1000 Subject: Clean up force unwraps and lets Wow, I didn't know `if let` was a thing back then, haha. Also made UIImage a bit safer in case asset is missing by unwrapping in one common place. --- foray/Scenes/ForayDetailViewController.swift | 4 ++-- foray/Scenes/ForayTableViewController.swift | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'foray/Scenes') diff --git a/foray/Scenes/ForayDetailViewController.swift b/foray/Scenes/ForayDetailViewController.swift index 1e2f9ca..52aa6b8 100644 --- a/foray/Scenes/ForayDetailViewController.swift +++ b/foray/Scenes/ForayDetailViewController.swift @@ -29,10 +29,10 @@ class ForayDetailViewController: UIViewController, HasCustomView, Coordinated { switch item.type { case .item: description += "Item" - image = UIImage(named: item.id)! + image = UIImage(named: item.id) ?? UIImage.fromAsset(.it) case .quest: description += "Quest" - image = UIImage(named: "spy")! + image = UIImage.fromAsset(.spy) } description += "\nID: " + item.id description += "\nReleased: " + item.releaseDateFormatted diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift index 849553c..3d839a1 100644 --- a/foray/Scenes/ForayTableViewController.swift +++ b/foray/Scenes/ForayTableViewController.swift @@ -87,13 +87,13 @@ class ForayTableViewController: UITableViewController, Coordinated { switch item.type { case .item: type = "Item" - icon = UIImage(named: item.id)! + icon = UIImage(named: item.id) ?? UIImage.fromAsset(.it) case .quest: type = "Quest" - icon = UIImage(named: "spy")! + icon = UIImage.fromAsset(.spy) } - let cell: ForayTableViewCell = tableView.dequeueReusableCell(withIdentifier: "ForayTableViewCell", for: indexPath) as! ForayTableViewCell + guard let cell = tableView.dequeueReusableCell(withIdentifier: "ForayTableViewCell", for: indexPath) as? ForayTableViewCell else { return ForayTableViewCell() } cell.setData(name: item.name, desc: type + "ID: " + item.id, img: icon) return cell } -- cgit