1

As my question states, I keep getting the error "extra argument 'forKey' in call" while trying to write this piece of code. Can someone please explain why?

var rgbOutputSettings:NSDictionary = NSDictionary(object: NSNumber(int: kCMPixelFormat_32BGRA), forKey: kCVPixelBufferPixelFormatTypeKey)
user3353890
  • 1,844
  • 1
  • 16
  • 31

3 Answers3

2

Breaking down your statement we get:

let obj = NSNumber(integer: kCMPixelFormat_32BGRA)
let key = kCVPixelBufferPixelFormatTypeKey
var rgbOutputSettings : NSDictionary = NSDictionary(object: obj, forKey: key)

The problem is that kCVPixelBufferPixelFormatTypeKey can be of more that a single type. Quoting the documentation (emphasis mine):

kCVPixelBufferPixelFormatTypeKey:

The pixel format for this buffer (type CFNumber, or type CFArray containing an array of CFNumber types (actually type OSType)).

I've converted into String to make it compile:

let key: String = kCVPixelBufferPixelFormatTypeKey as String

Maybe that's not want you need, if you need to achieve something like this

Community
  • 1
  • 1
Diego Freniche
  • 5,225
  • 3
  • 32
  • 45
2

kCVPixelBufferPixelFormatTypeKey is a CFStringRef and not an NSString. You need to cast it to an NSString, like so:

var formatKey = kCVPixelBufferPixelFormatTypeKey as NSString
var rgbOutputSettings:NSDictionary = NSDictionary(object: NSNumber(int: kCMPixelFormat_32BGRA), forKey: formatKey)
Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
0

In some cases, "Extra argument in call" is given even if the call looks right, if the types of the arguments don't match that of the function declaration.

Please refer to this question on SO

So you can use it as

var key = kCVPixelBufferPixelFormatTypeKey as NSString

Community
  • 1
  • 1
Amit Singh
  • 2,698
  • 21
  • 49