0

I want to write a swift 3 function which reads exif data from a photo (PHAsset). I am working with requestImageData call. This call does not seems to be synchronous, even if I set isSynchronous option to true.

What I want to do is to return a value from the handler block. This code does not work because my return isn't in the function body. This return is in the handler.

How should I do to make this function synchronous and to return the properties dictionary?

func read_exif(photo:PHAsset) -> [String:Any] {
    let manager = PHImageManager.default()
    let options = PHImageRequestOptions()
    options.isSynchronous = true
    manager.requestImageData(for: photo, options: options) { (result, string, orientation, info) -> Void in
        let img:CIImage = CIImage(data:result!)!
        return img.properties
    }
}
Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Bob5421
  • 7,757
  • 14
  • 81
  • 175
  • You might want to check [this answer](http://stackoverflow.com/questions/40714488/is-there-any-particular-use-of-closure-in-swift-and-whats-the-benefit/40715084#40715084), hope it will be -somehow- useful to you. – Ahmad F Dec 18 '16 at 08:22
  • 2
    use completion handler for such issue – Shobhakar Tiwari Dec 18 '16 at 08:26
  • I am sorry but those answers does not respond to my initial question. What i want to do is to make my read_exif function blocking and waiting until the result is returned... – Bob5421 Dec 20 '16 at 08:29

0 Answers0