类型 'OSType' 不符合 Swift 2.0 中的协议 'AnyObject'
Type 'OSType' does not conform to protocol 'AnyObject' in Swift 2.0
我刚刚使用 Swift 2.0 更新到 Xcode 7 beta。
当我将我的项目更新到 Swift 2.0 时,我得到了这个错误:"Type 'OSType' does not conform to protocol 'AnyObject' in Swift 2.0"。我的项目在 Swift 1.2 中完美运行。这是代码出错:
videoDataOutput = AVCaptureVideoDataOutput()
// create a queue to run the capture on
var captureQueue=dispatch_queue_create("catpureQueue", nil);
videoDataOutput?.setSampleBufferDelegate(self, queue: captureQueue)
// configure the pixel format
**videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA]** // ERROR here!
if captureSession!.canAddOutput(videoDataOutput) {
captureSession!.addOutput(videoDataOutput)
}
我尝试将 kCVPixelFormatType_32BGRA 转换为 AnyObject,但没有成功。任何人都可以帮助我吗?
对不起,我的英语不好!谢谢!
这是Swift中的kCVPixelFormatType_32BGRA
定义 1.2:
var kCVPixelFormatType_32BGRA: Int { get } /* 32 bit BGRA */
这是它在Swift 2.0:
中的定义
var kCVPixelFormatType_32BGRA: OSType { get } /* 32 bit BGRA */
实际上 OSType
是 UInt32
不能隐式转换为 NSNumber
:
When you write let ao: AnyObject = Int(1)
, it isn’t really putting an Int into an AnyObject. Instead, it’s implicitly converting your Int into an NSNumber, which is a class, and then putting that in.
所以试试这个:
videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA)]
或
videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: NSNumber(unsignedInt: kCVPixelFormatType_32BGRA)
我刚刚使用 Swift 2.0 更新到 Xcode 7 beta。 当我将我的项目更新到 Swift 2.0 时,我得到了这个错误:"Type 'OSType' does not conform to protocol 'AnyObject' in Swift 2.0"。我的项目在 Swift 1.2 中完美运行。这是代码出错:
videoDataOutput = AVCaptureVideoDataOutput()
// create a queue to run the capture on
var captureQueue=dispatch_queue_create("catpureQueue", nil);
videoDataOutput?.setSampleBufferDelegate(self, queue: captureQueue)
// configure the pixel format
**videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA]** // ERROR here!
if captureSession!.canAddOutput(videoDataOutput) {
captureSession!.addOutput(videoDataOutput)
}
我尝试将 kCVPixelFormatType_32BGRA 转换为 AnyObject,但没有成功。任何人都可以帮助我吗? 对不起,我的英语不好!谢谢!
这是Swift中的kCVPixelFormatType_32BGRA
定义 1.2:
var kCVPixelFormatType_32BGRA: Int { get } /* 32 bit BGRA */
这是它在Swift 2.0:
中的定义var kCVPixelFormatType_32BGRA: OSType { get } /* 32 bit BGRA */
实际上 OSType
是 UInt32
不能隐式转换为 NSNumber
:
When you write
let ao: AnyObject = Int(1)
, it isn’t really putting an Int into an AnyObject. Instead, it’s implicitly converting your Int into an NSNumber, which is a class, and then putting that in.
所以试试这个:
videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: Int(kCVPixelFormatType_32BGRA)]
或
videoDataOutput?.videoSettings = [kCVPixelBufferPixelFormatTypeKey: NSNumber(unsignedInt: kCVPixelFormatType_32BGRA)