【发布时间】:2017-09-13 03:29:27
【问题描述】:
长话短说,我正在实现 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!)
所以,我到现在为止做了什么:
- 清理项目(无效)
- 清理了构建文件夹(无效)
- 创建了一个新项目来实现这个委托(这个工作)
- 评论了不属于此委托的所有其他功能(无效)
- 在我的项目中创建了一个新的 ViewController,它只实现了这个委托(没有工作)
- 关闭 XCode 以确保这不是缓存问题(不起作用 =/)
- 试图在旧版本的 XCode 中运行项目
有时 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!) {
}
}
【问题讨论】:
-
显示与分配代理相关的代码。
-
这是我的班主任'class VideoViewController: PublishViewController, AVCaptureFileOutputRecordingDelegate'
-
你不需要
import UIKit吗? -
不一定,但我添加只是为了确保...继续显示相同的错误
-
既然您已经完成了清理项目,请尝试清理 XCode Derived Data
标签: ios xcode swift3 migration swift2.3