Objective-C 到 Swift 翻译问题
Objective-C to Swift translation issue
我正在尝试将这一行简单的代码翻译成 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
任何关于如何写这篇文章的建议 Swift 将不胜感激。
我相信会是:
let videoConnection: AVCaptureConnection = UnsafePointer<Int8>.null()
由于 Swift 有点向您隐藏了指针(除了对象实际上是对对象的指针引用)和直接指针操作,因此您有时不得不稍微扭曲一下自己。 :)
如果你想 "initialize" 带有 nil 的东西,它必须是可选的。
所以
var videoConnection: AVCaptureConnection? = nil
或
var videoConnection: AVCaptureConnection?
是对的。
我正在尝试将这一行简单的代码翻译成 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
任何关于如何写这篇文章的建议 Swift 将不胜感激。
我相信会是:
let videoConnection: AVCaptureConnection = UnsafePointer<Int8>.null()
由于 Swift 有点向您隐藏了指针(除了对象实际上是对对象的指针引用)和直接指针操作,因此您有时不得不稍微扭曲一下自己。 :)
如果你想 "initialize" 带有 nil 的东西,它必须是可选的。 所以
var videoConnection: AVCaptureConnection? = nil
或
var videoConnection: AVCaptureConnection?
是对的。