title: How to write Exif data to image in Swift with lat long
body: <p>I am trying to write EXIF data to the image but <strong>CGImageDestinationFinalize</strong> crashes:</p>
  
  <pre><code>var image = info[UIImagePickerControllerOriginalImage] as! UIImage
      let jpeg = UIImageJPEGRepresentation(image, 1.0)
      var source: CGImageSource? = nil
      source = CGImageSourceCreateWithData((jpeg as CFData?)!, nil)
      let metadata = CGImageSourceCopyPropertiesAtIndex(source!, 0, nil) as? [AnyHashable: Any]
      var metadataAsMutable = metadata
      var EXIFDictionary = (metadataAsMutable?[(kCGImagePropertyExifDictionary as String)]) as? [AnyHashable: Any]
      var GPSDictionary = (metadataAsMutable?[(kCGImagePropertyGPSDictionary as String)]) as? [AnyHashable: Any]
  
      GPSDictionary![(kCGImagePropertyGPSLatitude as String)] = 30.21313
      GPSDictionary![(kCGImagePropertyGPSLongitude as String)] = 76.22346
      EXIFDictionary![(kCGImagePropertyExifUserComment as String)] = "Hello Image"
  
  
  let UTI: CFString = CGImageSourceGetType(source!)!
      let dest_data = NSMutableData()
      let destination: CGImageDestination = CGImageDestinationCreateWithData(dest_data as CFMutableData, UTI, 1, nil)!
      CGImageDestinationAddImageFromSource(destination, source!, 0, (metadataAsMutable as CFDictionary?))
      CGImageDestinationFinalize(destination)
  </code></pre>