简体   繁体   English

从Objective-C到Swift的翻译问题

[英]Objective-C to Swift translation issue

I'm trying to translate this simple line of code to Swift, but can't figure out how to write it: 我正在尝试将这行简单的代码转换为Swift,但无法弄清楚如何编写它:

AVCaptureConnection *videoConnection = nil;

I've tried: 我试过了:

    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

Any suggestions on how to write this is Swift would be appreciated. 关于如何编写此Swift的任何建议将不胜感激。

If you want to "initialize" something with nil it has to be an Optional. 如果要使用nil“初始化”某些东西,则必须是可选的。 So 所以

var videoConnection: AVCaptureConnection? = nil

or 要么

var videoConnection: AVCaptureConnection?

would be right. 是正确的。

I believe it would be: 我相信它将是:

let videoConnection: AVCaptureConnection = UnsafePointer<Int8>.null()

Since Swift sort of conceals pointers from you (except that objects are really pointer references to the objects) and direct pointer manipulation, you sometimes have to contort yourself a bit. 由于Swift会向您隐瞒指针(对象实际上是对对象的指针引用)和直接的指针操作,因此有时您必须扭曲一下自己。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM