title: How can I convert from UIImage to HEIF / HEIC Data in Swift?
body: <p>Is <code>NSKeyedArchiver</code> appropriate to convert <code>UIImage</code> to <code>Data</code>?</p>
  
  <pre><code>do {
      let data = try NSKeyedArchiver.archivedData(withRootObject: UIImage(named: somePath), requiringSecureCoding: true)
      ...
  } catch {
      print(error)
  }
  </code></pre>
  
  <p>Or is it overkill and using <code>pngData()</code> is more appropriate?</p>
  
  <pre><code>let image = UIImage(named: somePath)
  let data = image?.pngData()
  </code></pre>
  
  <p>and how can I convert from <code>UIImage</code> to HEIF / HEIC <code>Data</code> ?</p>
  
  <p>The goal is to save the image to the device's file system.</p>