aboutsummaryrefslogtreecommitdiff
path: root/foray/Presenters
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-07-17 02:25:12 +1000
committerNicholas Tay <nick@windblume.net>2022-07-17 02:25:12 +1000
commitbd7761216a065b0dd859cb19d709996739a240cd (patch)
tree8b1d33034f8c212613d7a07b864d1688b8c080d2 /foray/Presenters
parent1adbed9f8b94521befd237c14d36325a55037a41 (diff)
downloadforayios-bd7761216a065b0dd859cb19d709996739a240cd.tar.gz
forayios-bd7761216a065b0dd859cb19d709996739a240cd.tar.bz2
forayios-bd7761216a065b0dd859cb19d709996739a240cd.zip
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.
Diffstat (limited to 'foray/Presenters')
-rw-r--r--foray/Presenters/PenguinItemPresenter.swift9
1 files changed, 3 insertions, 6 deletions
diff --git a/foray/Presenters/PenguinItemPresenter.swift b/foray/Presenters/PenguinItemPresenter.swift
index 1d617bf..45b970c 100644
--- a/foray/Presenters/PenguinItemPresenter.swift
+++ b/foray/Presenters/PenguinItemPresenter.swift
@@ -16,12 +16,9 @@ class PenguinItemPresenter {
let fetcher = ForayFetcher()
func fetch() async -> [PenguinItemViewModel] {
- do {
- let apiItems: [PenguinItemModel] = try await fetcher.fetch(url: Constants.apiEndpoint)
- return transform(models: apiItems)
- } catch {
- return []
- }
+ guard let endpoint = URL(string: Constants.apiEndpoint),
+ let apiItems: [PenguinItemModel] = try? await fetcher.fetch(url: endpoint) else { return [] }
+ return transform(models: apiItems)
}
func transform(models: [PenguinItemModel]) -> [PenguinItemViewModel] {