I am developing an application with a custom camera and there I have used captureOutput method(Lets say A) which is a delegate method of AVCaptureVideoDataOutputSampleBufferDelegate.
I have used another function (Lets say B) which behaves like setTimeout in javascripts.
When I call B inside A it is not getting called.
Here is my code
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
setTimeout(1) { () -> Void in
//piece of code i want to run
}
}
func setTimeout(delay:NSTimeInterval, block:()->Void) -> NSTimer {
return NSTimer.scheduledTimerWithTimeInterval(delay, target: NSBlockOperation(block: block), selector: "main", userInfo: nil, repeats: false);
}
When I call setTimeout method inside viewDidLoad() it is working fine. But inside this particular method it is not getting called. Can someone give me a solution for this. Any help would be highly appreciated.
Edited: Confusing about the reason why my code is not working. Any idea?
I was able to find a way to get my work done.But couldn't find what is wrong with my previous code. This is how it looks like
func captureOutput(captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, fromConnection connection: AVCaptureConnection!) {
let seconds: Int64 = 1 * Int64(NSEC_PER_SEC);
let time = dispatch_time(DISPATCH_TIME_NOW, seconds);
dispatch_after(time, dispatch_get_main_queue(), {
//piece of code i want to run
});
}