title: Cancel a PHImageRequest launched via an Operation
body: <p>I have an OperationQueue where I launch multiple PHImageRequest in order to load images (via an Operation). But I want to cancel the request if I don't need the image anymore (images are in a collectionView). Initially I wanted to watch the isCancelled variable but it's not possible as I cannot override it...
  I tried to put a loop after the request that loop while the request is not finished and check if isCancelled is true, if it is, it cancel the image request (I got rid of this solution, it was causing too many bugs, images were not loading..).</p>
  
  <p>I come up with a solution, but there is only a short time where isCancelled can cancel the image request.  </p>
  
  <p>If anyone has a proper way to cancel the request, I'm here Thanks!</p>
  
  <p>First idea (loop):</p>
  
  <pre><code>override func start() {
          if isCancelled { return }
          var imageRequested = true
  
          requestId = HomeViewController.imageManager.requestImage(
              for: mAsset.phasset,
              targetSize: CGSize(width: 200, height: 200),
              contentMode: .default,
              options: UIConstants.fastAssetRequestOptions,
              resultHandler: { [weak self] (result, _) -&gt; Void in
                  guard let self = self else { return }
                  guard let result = result else { return }
                  self.image = result
  
                  imageRequested = false              
  
                  if let loadingCompleteHandler = self.imageLoadingCompleteHandler {
                      DispatchQueue.main.async {
                          loadingCompleteHandler(result)
                      }
                  }
              }
          )
          while imageRequested {
              if isCancelled &amp;&amp; requestId != nil {
                  manager.cancelImageRequest(requestId!)
                  requestId = nil
              }
          }
      }
  </code></pre>
  
  <p>Second idea (current solution): </p>
  
  <pre><code>override func start() {
          if isCancelled { return }        
          requestId = HomeViewController.imageManager.requestImage(
              for: mAsset.phasset,
              targetSize: CGSize(width: 200, height: 200),
              contentMode: .default,
              options: UIConstants.fastAssetRequestOptions,
              resultHandler: { [weak self] (result, _) -&gt; Void in
                  guard let self = self else { return }
                  guard let result = result else { return }
                  self.image = result
  
                  if let loadingCompleteHandler = self.imageLoadingCompleteHandler {
                      DispatchQueue.main.async {
                          loadingCompleteHandler(result)
                      }
                  }
              }
          )
  
          if(isCancelled &amp;&amp; (requestId != nil)) {
              HomeViewController.imageManager.cancelImageRequest(requestId!)
          }
      }
  </code></pre>