Delegate Events


Celestial's URLImageView and URLVideoPlayerView provide delegates for observing events throughout the process of downloading and caching media.

One exception: The URLVideoPlayerView's URLVideoPlayerViewDelegate delegate subclasses the URLCachableViewDelegate and provides extra functionality. See below

URLCachableViewDelegate


Download Completion

Notifies receiver that a download has completed

  • Parameters:
  • view: The view that will send delegate information to its receiver
  • media: The media that just finished downloading.
    • For URLImageView images, this can be type-casted to a UIImage
    • For URLVideoPlayerView, this can be type-casted to a URL

However, this for formality. There is no need to manually set the image or video in the respective URLImageView or URLVideoPlayerView once download completes

@objc optional func urlCachableView(_ view: URLCachableView, didFinishDownloading media: Any)
Download Progress

Notifies receiver of download progress prior to completion

  • Parameters:
  • view: The view that will send delegate information to its receiver
  • progress: Float value from 0.0 to 1.0 denoting current download progress of the requested resource
  • humanReadableProgress: A more easily readable version of the progress parameter
@objc optional func urlCachableView(_ view: URLCachableView, 
                                    downloadProgress progress: Float, 
                                    humanReadableProgress: String)
Errors

Notifies receiver of errors encountered during download and/or caching

  • Parameters:
  • view: The view that will send delegate information to its receiver
  • error: Error encountered during download and possible caching
@objc optional func urlCachableView(_ view: URLCachableView, downloadFailedWith error: Error)

Example

class ImageCell: UICollectionViewCell {

    let imageView = URLImageView(delegate: self, cacheLocation: .inMemory)

    // ...
}

extension ImageCell: URLCachableViewDelegate {

    func urlCachableView(_ view: URLCachableView, didFinishDownloading media: Any) {
        // Download completed!
    }
    
    func urlCachableView(_ view: URLCachableView, downloadFailedWith error: Error) {
        // Inspect the error
    }
    
    func urlCachableView(_ view: URLCachableView, downloadProgress progress: Float, humanReadableProgress: String) {
        // Update progress bar, UI, etc.
    }
}

URLVideoPlayerViewDelegate


Notifies receiver that the URLVideoPlayerView is ready to begin playing the video

@objc optional func urlVideoPlayerIsReadyToPlay(_ view: URLVideoPlayerView)