Skip to content

Commit

Permalink
Move UIImage creation to a tryMake extension
Browse files Browse the repository at this point in the history
  • Loading branch information
grav0211 committed Oct 6, 2022
1 parent f59e4ae commit 31f80b7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions EssentialApp/EssentialApp/FeedViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ final class FeedViewAdapter: ResourceView {
resourceView: WeakRefVirtualProxy(view),
loadingView: WeakRefVirtualProxy(view),
errorView: WeakRefVirtualProxy(view),
mapper: { data in
guard let image = UIImage(data: data) else {
throw InvalidImageData()
}
return image
})
mapper: UIImage.tryMake
)

return view
})
}
}

private struct InvalidImageData: Error {}
extension UIImage {
struct InvalidImageData: Error {}

static func tryMake(data: Data) throws -> UIImage {
guard let image = UIImage(data: data) else {
throw InvalidImageData()
}
return image
}
}

0 comments on commit 31f80b7

Please sign in to comment.