return value in function handler with swift 3

52 views Asked by At

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
    }
}
0

There are 0 answers