AVCaptureFileOutputRecordingDelegate in Xcode8

Asked 2 years ago, Updated 2 years ago, 94 views

import UIKit
import AVKit
import AVFoundation
import AssetsLibrary

vardocumentsPath = NSTemporaryDirectory()
varfileName: String?=""

classVideoDelegate:NSObject, AVCaptureFileOutputRecordingDelegate{
    func captureOutput (captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL:NSURL!, fromConnections connections:[AnyObject]!, error:NSError!) {
        print("capture output: finish recording to\(outputFileURL)")
    }

    func captureOutput (captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL:NSURL!, fromConnections: AnyObject!) {
        print("capture output:started recording to\(fileURL)")

    }
}

I wrote this code up to Xcode7, but
Type 'VideoDelegate' does not conform to protocol 'AVCaptureFileOutputRecordingDelegate'
I have never received an error like this.
Can't I use it with Xcode8Swift3?

swift xcode swift3

2022-09-30 17:55

1 Answers

This is because the Swift3 naming convention has changed the external argument name and type.

class VideoDelegate:NSObject, AVCaptureFileOutputRecordingDelegate{

    func capture(_captureOutput:AVCaptureFileOutput!, didFinishRecordingToOutputFileAtoutputFileURL:URL!, fromConnections connections:[AnyObject]!, error:NSError!){
        print("capture output: finish recording to\(outputFileURL)")
    }

    func capture(_captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtoutputFileURL:URL!, fromConnections connections:[AnyObject]!) {
        print("capture output:started recording to\(outputFileURL)")
    }
}

You must add _ to make it clear that the first argument label is no longer omitted and that you do not want to take the argument label instead.

didStartRecordingToOutputFileAtURL: changed to didStartRecordingToOutputFileAt: and NSURL changed to URL.

AVCaptureFileOutputRecordingDelegate definition should be reviewed quickly.

For more information, please visit here.


2022-09-30 17:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.