Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dispatchqueue in swift 3 appears as unresolved identifier [duplicate]

I am trying to take/record video asynchronously on the main thread. However, when I call dispatch.main.async, I always get the error:

use of unresolved identifier DispatchQueue

I've looked everywhere from WWDC to Apple's Documentation, but I see no evidence of the type being deprecated.

Here is the code:

   if !self.cameraEngine.isRecording {
            if let url = CameraEngineFileManager.temporaryPath("video.mp4") {
                self.cameraButton.setTitle("stop recording", forState: [])
                self.cameraEngine.startRecordingVideo(url, blockCompletion: { (url: NSURL?, error: NSError?) -> (Void) in
                    if let url = url {

                        DispatchQueue.main.async {
                            self.cameraButton.setTitle("start recording", for: .normal)
                            CameraEngineFileManager.saveVideo(url, blockCompletion: { (success: Bool, error: Error?) -> (Void) in
                                if success {
                                    let alertController =  UIAlertController(title: "Success, video saved !", message: nil, preferredStyle: .alert)
                                    alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
                                    self.present(alertController, animated: true, completion: nil)
                                }
                            })
                        }
                    }
                })
            }
        }
        else {
            self.cameraEngine.stopRecordingVideo()
        }
    }
like image 435
NightHawk95 Avatar asked Sep 24 '16 17:09

NightHawk95


1 Answers

You can either put

import Foundation 

or

import Dispatch

at the beginning of your code to start using DispatchQueue class without any issue.

like image 122
Wilson Avatar answered Oct 19 '22 23:10

Wilson