将 Objective C 转换为 swift 时出错
Error on conversion Objective C to swift
我的Objective C代码:
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[self.videoDataOutput setVideoSettings:rgbOutputSettings];
试了很多次还是报错。
我就是这样试的。
Swift:
var rgbOutputSettings: [NSObject: AnyObject] = kCVPixelBufferPixelFormatKey as! AnyObject: Int(kCMPixelFormat_32BGRA)]
self.videoOutput = rgbOutputSettings
错误:无法为 "int.init" 找到接受所提供参数的重载
尝试以下:
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey : Int(kCVPixelFormatType_32BGRA)]
var rgbOutputSettings = NSDictionary(objects: NSNumber(int: Int(kCMPixelFormat_32BGRA)), forKeys: kCVPixelBufferPixelFormatTypeKey)
self.videoDataOutput.setVideoSettings(rgbOutputSettings)
试试这个
let rgbOutputSettings = [kCVPixelBufferPixelFormatTypeKey as NSString : NSNumber.init(unsignedInt: kCMPixelFormat_32BGRA)] as NSDictionary
self.videoOutput = rgbOutputSettings
我的Objective C代码:
NSDictionary *rgbOutputSettings = [NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCMPixelFormat_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey];
[self.videoDataOutput setVideoSettings:rgbOutputSettings];
试了很多次还是报错。 我就是这样试的。
Swift:
var rgbOutputSettings: [NSObject: AnyObject] = kCVPixelBufferPixelFormatKey as! AnyObject: Int(kCMPixelFormat_32BGRA)]
self.videoOutput = rgbOutputSettings
错误:无法为 "int.init" 找到接受所提供参数的重载
尝试以下:
videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey : Int(kCVPixelFormatType_32BGRA)]
var rgbOutputSettings = NSDictionary(objects: NSNumber(int: Int(kCMPixelFormat_32BGRA)), forKeys: kCVPixelBufferPixelFormatTypeKey)
self.videoDataOutput.setVideoSettings(rgbOutputSettings)
试试这个
let rgbOutputSettings = [kCVPixelBufferPixelFormatTypeKey as NSString : NSNumber.init(unsignedInt: kCMPixelFormat_32BGRA)] as NSDictionary
self.videoOutput = rgbOutputSettings