Search code examples
swiftphotosframework

Understanding swift typealias


As part of Photos framework, there is an options to download photos from iCloud(if needed). The problem is that i don't understand how to use it.

The docs says :

var progressHandler: PHAssetImageProgressHandler?

Where PHAssetImageProgressHandler is

The signature for a block that Photos calls while downloading asset data from iCloud. Used by the progressHandler property.

typealias PHAssetImageProgressHandler = (Double, NSError?, UnsafeMutablePointer<ObjCBool>, [NSObject : AnyObject]?) -> Void

But i have no idea how to integrate it, any suggestions folks?

UPDATE

the request i'm using

      var options: PHImageRequestOptions = PHImageRequestOptions()
      options.networkAccessAllowed = true
        options.progressHandler = PHAssetImageProgressHandler {

        }

Solution

  • It's used as a closure in the class PHImageRequestOptions which is passed for example to requestImageForAsset:targetSize:contentMode:options: of PHImageManager.

    The syntax looks like

    let finalRequestOptions = PHImageRequestOptions()
    finalRequestOptions.progressHandler = { (progress, error, stop, info) in
      // do something with the returned parameters
    }
    

    The documentation says:

    If you request an image whose data is not on the local device, and you have enabled downloading with the networkAccessAllowed property, Photos calls your block periodically to report progress and to allow you to cancel the download.

    There is a good description of PHImageManager on nshipster