Peter-Schorn/SpotifyAPI

Add a loadUIImage function

storiolo opened this issue · 0 comments

Maybe I'm not the only one who need Spotify image in UIImage type instead of Image type.
Thus, I suggest to add a function:

 func loadUIImage() -> AnyPublisher<UIImage, Error> {

    let publisher = URLSession.shared.dataTaskPublisher(
        for: self.url
    )

    return publisher
        .tryMap { data, response -> UIImage in

            if let image = PlatformImage(data: data).map({
                image -> UIImage in
            }) {
                return image
            }
            throw SpotifyGeneralError.other(
                "couldn't convert data to image"
            )

        }
        .eraseToAnyPublisher()      
 }

Here is an example, actually working on my project.
What do you think ?