I would like to pass a integer to a completion handler. Because the handler is asynchronous the value of count might be inaccurate by the time the completion handler gets a chance to run? I would like to pass the CURRENT value of count to the handler so that count is accurate when the handler is called. How do I do this?
// Take image
func didPressTakePhoto(){
if let videoConnection = stillImageOutput?.connection(withMediaType: AVMediaTypeVideo){
videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
count = count + 1
//Capture image. everything in this closure is ASYNCHRONOUS?
stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {
(sampleBuffer, error) in
//Do something with count...
})
}
}