参见英文答案 >
Swift 3.0 unresolved identifier for DispatchQueue2个
我试图在主线程上异步拍摄/录制视频.但是,当我调用dispatch.main.async时,我总是收到错误:
我试图在主线程上异步拍摄/录制视频.但是,当我调用dispatch.main.async时,我总是收到错误:
use of unresolved identifier dispatchQueue
从WWDC到Apple的文档我到处都是,但我看不到这种类型被弃用的证据.
这是代码:
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() } }
解决方法
你可以放
import Foundation
要么
import dispatch
在代码的开头,开始使用dispatchQueue类没有任何问题.