Downloading Images in SwiftUI

preview_player
Показать описание
In this video, Mohammad Azam will demonstrate how to download images in SwiftUI by building a SwiftUI custom Image view.

If you want to support my work then please consider buying one of my courses below. The links below already have coupons attached which will give you the best deal possible. Thank you for your support!

Patreon

Testing iOS Apps - Behavior Driven Development Using Swift

Machine Learning and Artificial Intelligence Using Swift

SwiftUI - Declarative Interfaces for any Apple Device

Flutter and Dart - Build Apps Using MVVM Design Pattern

Mastering RxSwift in iOS

MVVM Design Pattern Using Swift in iOS

Mastering ARKit for iOS

Intermediate and Advanced iOS - Build Real World Apps

The Complete Guide to JSON Parsing in Swift

Data Structures and Algorithms in Swift

Design Patterns in iOS Using Swift

Mastering MapKit for iOS

Machine Learning in iOS Using Swift

Mastering Firebase for iOS Using Swift

Mastering Server Side Swift Using Vapor 3

NodeJS - The Complete Developer Bootcamp

The Complete Guide to Lean Controllers in iOS
Рекомендации по теме
Комментарии
Автор

Absolutely excellent tutorial. 👍🏻
Thank you very much.

bssgkmsd
Автор

Let's say I'm getting the image url from a json file. After decoding the data of that json file how should I call this function "downloadImage" that downloads the image?

abdou
Автор

Have followed you tutorials and they're great. I need some help with Image(uiImage: UIImage(data: data)!) I get a Fatal error: Unexpectedly found nil while unwrapping an Optional value.! Any help would be appreciated.

yokohibarashi
Автор

Good video, thanks.
Regarding the use of bang and UIImage... it is possible that the downloaded data is an invalid image for some reason. The server, database, universe might be having a a bad day.
Therefore, I suggest that instead of the Image Service providing plain data, it should always provide a fully valid UIImage instance. (Or, a soft error is produced.)
Speaking of URLs, I suggest that all call sites are required to pass in a (fully validated) URL, rather than a string. (If the URL creation fails, it's a programmer error.) This reduces a lot of ambiguity along the chain.
Regards.

wmblemania
Автор

Its absolutely not safe to force unwrap, especially when you are getting object from service. The first thing is the data is not always 100 % reliable. In your case you are also not checking if image data is of type URL. Checking for string object don't always guarantee for valid URL. Please use optional binding. You can also use Throw statement in case to get this information in Log which is handy for debugging.

ashim
join shbcf.ru