title: iOS Swift 4: Get Image Format (JPG,PNG,GIF) From didFinishPickingMediaWithInfo
body: <p>I'm building an app that allows you to upload images from your library to the server. This server is used as essentially an image repository. For this reason, it's absolutely necessary to store it in it's original image format: Either JPG, PNG, or GIF. I.E. If the PNG image has transparency, that HAS to be preserved, it cannot simply be converted to a JPG.</p>
  
  <p>I USED to get the image format using UIImagePickerControllerReferenceURL:</p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
          let selectedImage = info[UIImagePickerControllerEditedImage] as! UIImage
          let assetPath = info[UIImagePickerControllerReferenceURL] as! NSURL
  
          if (assetPath.absoluteString?.hasSuffix("JPG"))! {
              print("JPG")
          }
          else if (assetPath.absoluteString?.hasSuffix("PNG"))! {
              print("PNG")
          }
          else if (assetPath.absoluteString?.hasSuffix("GIF"))! {
              print("GIF")
          }
          else {
              print("Unknown")
          }
  
          self.dismiss(animated: true, completion: nil)
  
          self.showImageFieldModal(selectedImage: selectedImage)
      }
  </code></pre>
  
  <p>But UIImagePickerControllerReferenceURL has been deprecated in iOS11. It suggests using UIImagePickerControllerPHAsset, but that's not a URL. I'm not sure what I'm supposed to do with that as a PHAsset object...</p>