Getting an error when converting UIImage to NSSString via NSData
<p>I'm trying to convert my <code>UIImage</code> from a <code>UIImageView</code> to a string as the data is stored as Base64. I'm using the method below to convert the image but it falls over when trying to update convertedStr. </p>

<pre><code>func convertImg() {
    let imageData: NSData = UIImagePNGRepresentation(imageView.image!)! as NSData
    convertedStr = NSString(data: imageData as Data, encoding: String.Encoding.utf8.rawValue)!
}
</code></pre>

<p>This function is about version 10 as I've tried different ways but the result is always the same. The error returned is </p>

<blockquote>
  <p>'fatal error: unexpectedly found nil while unwrapping an Optional
  value' and</p>
  
  <p>'function signature specialization ) -> ()
  to @callee_owned (@unowned Swift.UnsafeBufferPointer) ->
  (@out ()), Argument Types : [@callee_owned (@unowned
  Swift.UnsafeBufferPointer) -> ()]> of generic
  specialization  of
  Swift.StaticString.withUTF8Buffer 
  ((Swift.UnsafeBufferPointer) -> A) -> A'</p>
</blockquote>

<p>Could it be that the method I'm using requires a png file and won't work with <code>UIImage</code>?</p>