Conversion [NSNumber numberWithUnsignedInt: kCVPixelFormatType_32BGRA], (id) kCVPixelBufferPixelFormatTypeKey, nil]; to Swift

Getting the error here. Stop my brain. I tried all kinds of combinations.

Cannot find initializer for type NSDictionary that accepts a list of arguments of type '(object: (Int), forKey: CFString!)'

// configure the pixel format -  Obj-C
// videoOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey, nil];

// Swift       
videoOutput.videoSettings = NSDictionary(object: Int(kCVPixelFormatType_32BGRA), forKey:kCVPixelBufferPixelFormatTypeKey)
+4
source share
2 answers

update: Xcode 7.0 • Swift 2.0

videoOutput.videoSettings = NSDictionary(object: Int(kCVPixelFormatType_32BGRA), forKey: kCVPixelBufferPixelFormatTypeKey as String) as [NSObject : AnyObject]

or simply

videoOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey : Int(kCVPixelFormatType_32BGRA)]
+11
source

It looks like the type will be [String: Int].

Actually, looking at the Xcode docs, he says that this value can be either a single number or an array. If it is an array, then the type will be [String: [Int]].

, :

let aVideoSetting: [String: Int] =
[kCVPixelBufferPixelFormatTypeKey: kCVPixelFormatType_32BGRA] videoOutput.videoSettings = aVideoSetting

100% Cocoa Swift, , .

NSDictonary :

let aPixelFormat = NSNumber(int: kCVPixelFormatType_32BGRA)
let settingsDict = NSDictionary(aPixelFormat 
  forKey:  "numberWithUnsignedInt:kCVPixelFormatType_32BGRA")
0

Source: https://habr.com/ru/post/1583884/


All Articles