title: How to retrieve Custom values to Image metadata in swift 4?
body: <p>Am creating an application for image share related things. Here my requirement is <strong>I have to store some custom information(Name, PhoneNumber, Price) into the Image Metadata and retrieve it back</strong>.</p>
  
  <p>I use UIImagePickerController to capture the image and set my information into the image metadata in UIImagePickerControllerDelegate like below mentioned:</p>
  
  <pre><code>func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
      picker.dismiss(animated: true, completion: nil)
      let profileImage = info[UIImagePickerControllerOriginalImage] as? UIImage
      let imageData: Data = UIImageJPEGRepresentation(profileImage!, 1)!
      let cgImgSource: CGImageSource = CGImageSourceCreateWithData(imageData as CFData, nil)!
      let uti: CFString = CGImageSourceGetType(cgImgSource)!
      let dataWithExif: NSMutableData = NSMutableData(data: imageData)
      let destination: CGImageDestination = CGImageDestinationCreateWithData((dataWithExif as CFMutableData), uti, 1, nil)!
      let imageProoperties = CGImageSourceCopyPropertiesAtIndex(cgImgSource, 0, nil)! as NSDictionary
      let mutable: NSMutableDictionary = imageProoperties.mutableCopy() as! NSMutableDictionary
  
      let EXIFDictionary: NSMutableDictionary = (mutable[kCGImagePropertyExifDictionary as String] as? NSMutableDictionary)!
      print("Before Modification: \(EXIFDictionary)")
      EXIFDictionary[kCGImagePropertyExifUserComment as String] = "\(self.m_NameTxtFd.text!):\(self.m_PhoneNumberTxtFd.text!):\(self.m_PriceTxtFd.text!)"
      mutable[kCGImagePropertyExifDictionary as String] = EXIFDictionary
  
      CGImageDestinationAddImageFromSource(destination, cgImgSource, 0, (mutable as CFDictionary))
      CGImageDestinationFinalize(destination)
  
      let testImage: CIImage = CIImage(data: dataWithExif as Data, options: nil)!
      let newProperties: NSDictionary = testImage.properties as NSDictionary
      print("After Modification : \(newProperties)") //Here I Got My Information is Stored Successfully
  
      self.m_ImgView.image = self.convert(cmage: testImage)
      self.saveImageDocumentDirectory()
  }
  
      func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
          picker.dismiss(animated: true, completion: nil)
      }
  </code></pre>
  
  <p>Now am going to save the image in NSDocumentDirectory like below mentioned:</p>
  
  <pre><code>func saveImageDocumentDirectory(){
          let fileManager = FileManager.default
          let paths = (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString).appendingPathComponent("apple.jpg")
          let image = self.m_ImgView.image
          print(paths)
          let imageData = UIImageJPEGRepresentation(image!, 0.5)
          fileManager.createFile(atPath: paths as String, contents: imageData, attributes: nil)
      }
  </code></pre>
  
  <p>Now am going to fetch the stored image in another view controller like below mentioned: </p>
  
  <pre><code>func getImage(){
          let fileManager = FileManager.default
          let imagePAth = (self.getDirectoryPath() as NSString).appendingPathComponent("apple.jpg")
          print(imagePAth)
          if fileManager.fileExists(atPath: imagePAth){
              self.m_ImgView.image = UIImage(contentsOfFile: imagePAth)
              self.fetchImageDetails()
          }else{
              print("No Image")
          }
      }
  </code></pre>
  
  <p>I successfully got the image and now I have to fetch the information from image metadata like below mentioned:</p>
  
  <pre><code>func fetchImageDetails() {
          let profileImage = self.m_ImgView.image!
          let ciImage: CIImage = CIImage(cgImage: profileImage.cgImage!)
          let newProperties: NSDictionary = ciImage.properties as NSDictionary
      }
  </code></pre>
  
  <p>But issue is the information is null in image property.</p>
  
  <p>Please guide me to retrieve the custom information from stored Image.</p>