长话短说,我实现了AVCaptureFileOutputRecordingDelegate,但XCode并没有认识到所需的方法。
自从我开始将代码迁移到Swift 3后,实现此委托的类继续发出错误
Type 'VideoViewController' does not conform to protocol 'AVCaptureFileOutputRecordingDelegate'
我知道我只需要实现这个方法
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!)
所以,到目前为止我做了什么:
有时候XCode建议修复它来实现"缺失"方法
/*!
@method captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:
@abstract
Informs the delegate when all pending data has been written to an output file.
@param captureOutput
The capture file output that has finished writing the file.
@param fileURL
The file URL of the file that has been written.
@param connections
An array of AVCaptureConnection objects attached to the file output that provided the data that was written to the file.
@param error
An error describing what caused the file to stop recording, or nil if there was no error.
@discussion
This method is called when the file output has finished writing all data to a file whose recording was stopped, either because startRecordingToOutputFileURL:recordingDelegate: or stopRecording were called, or because an error, described by the error parameter, occurred (if no error occurred, the error parameter will be nil). This method will always be called for each recording request, even if no data is successfully written to the file.
Clients should not assume that this method will be called on a specific thread.
Delegates are required to implement this method.
*/
@available(iOS 4.0, *)
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
}
但在此之后,XCode说该方法是重复的,并且仍然说该类没有实现所需的方法
任何人都知道为什么会这样,以及如何解决它?
谢谢大家
编辑1
这是我在我的项目中创建的类,用于测试并发生相同的错误
import Foundation
import AVFoundation
class VVC : UIViewController, AVCaptureFileOutputRecordingDelegate {
/*!
@method captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:
@abstract
Informs the delegate when all pending data has been written to an output file.
@param captureOutput
The capture file output that has finished writing the file.
@param fileURL
The file URL of the file that has been written.
@param connections
An array of AVCaptureConnection objects attached to the file output that provided the data that was written to the file.
@param error
An error describing what caused the file to stop recording, or nil if there was no error.
@discussion
This method is called when the file output has finished writing all data to a file whose recording was stopped, either because startRecordingToOutputFileURL:recordingDelegate: or stopRecording were called, or because an error, described by the error parameter, occurred (if no error occurred, the error parameter will be nil). This method will always be called for each recording request, even if no data is successfully written to the file.
Clients should not assume that this method will be called on a specific thread.
Delegates are required to implement this method.
*/
@available(iOS 4.0, *)
func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
}
}
答案 0 :(得分:0)
不确定这是否是您的问题的原因,但我遇到了同样的问题,这是由于 Candidate has non matching type
错误造成的。
我创建了一个名为 Error
的新类型,它的完整命名空间名称为 [Namespace].Error
,这与 Swift 的 Error
类型相冲突。
在实现 AVCaptureFileOutputRecordingDelegate
时 XCode 将添加协议函数签名并且 didFinishRecordingTo
函数具有 Error
类型。我不得不将其更改为 Swift.Error
func fileOutput(
_ output: AVCaptureFileOutput,
didFinishRecordingTo outputFileURL: URL,
from connections: [AVCaptureConnection],
error: Swift.Error?
) {
...
}