title: iOS - Swift 3 Share Extension Preview Image
body: <p>I'm currently building a share extension that accepts URLs. As part of this I've customised my share screen as outlined in a previous question to create a full screen view controller. This is all working fine. However in the default share composer view I noticed there was a preview image of the web page. I'm trying to access this in my extension but I can't seem to get hold of it.</p>
  
  <p>Specifically I've been trying to use the method </p>
  
  <p><code>loadPreviewImage</code></p>
  
  <p><a href="https://developer.apple.com/reference/foundation/nsitemprovider/1403925-loadpreviewimage" rel="noreferrer">https://developer.apple.com/reference/foundation/nsitemprovider/1403925-loadpreviewimage</a></p>
  
  <p>You will note in the docs that this says the following for the completion handler </p>
  
  <blockquote>
    <p>completion​Handler
    A completion handler block to execute with the results. The first parameter of this block must be a parameter of type NSData, NSURL, UIImage (in iOS), or NSImage (in macOS) for receiving the image data. For more information about implementing the block, see Completion​Handler.</p>
  </blockquote>
  
  <p>However if I try to set this as a UIImage in my completion block I get an error of </p>
  
  <blockquote>
    <p>Cannot convert value of type '(UIImage, _) -> ()' to expected argument
    type 'NSItemProvider.CompletionHandler!'</p>
  </blockquote>
  
  <p>example code where itemProvider is confirmed to be an instance of NSItemProvider via guard statements</p>
  
  <pre><code>itemProvider.loadPreviewImage(options: nil) { (image: UIImage, error) in    
          }
  </code></pre>
  
  <p>The docs for the completion Handler say to set this to what type you want and it will attempt to coerce the data to the type you specify. Has anyone seen this before? I'm not sure what to do here as I can't see what I'm doing wrong.</p>
  
  <p><a href="https://developer.apple.com/reference/foundation/nsitemprovider/completionhandler" rel="noreferrer">https://developer.apple.com/reference/foundation/nsitemprovider/completionhandler</a></p>
  
  <p>If all else fails I'll look at using some Javascript to get an image from the dom but I would have liked the preview image that Apple seemed to provide</p>