我正试图将这一行简单的代码转换为Swift,但不知道如何编写:

AVCaptureConnection *videoConnection = nil;

我试过:
    let videoConnection: AVCaptureConnection = nil

    let videoConnection: AVCaptureConnection = false

    var videoConnection:AVCaptureConnection = AVCaptureConnection()
            videoConnection = nil

    var videoConnection:AVCaptureConnection = AVCaptureConnection()
            videoConnection = false

var videoConnection:AVCaptureConnection = AVCaptureConnection()
            videoConnection.active = false

var videoConnection:AVCaptureConnection = AVCaptureConnection()
            videoConnection.active = nil

关于如何写这篇文章的任何建议都将不胜感激。

最佳答案

如果你想用nil“初始化”一些东西,它必须是可选的。
所以

var videoConnection: AVCaptureConnection? = nil


var videoConnection: AVCaptureConnection?

是的。

08-17 09:08