Peter-Schorn / SpotifyAPI

A Swift library for the Spotify web API. Supports all endpoints.
https://peter-schorn.github.io/SpotifyAPI/documentation/spotifywebapi
MIT License
269 stars 33 forks source link

Add a loadUIImage function #48

Closed storiolo closed 1 year ago

storiolo commented 1 year ago

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 ?