user3353890
user3353890

Reputation: 1891

NSDictionary extra argument "forKey" in call

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)

Upvotes: 1

Views: 262

Answers (3)

Amit Singh
Amit Singh

Reputation: 2698

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

Upvotes: 0

Gordon Childs
Gordon Childs

Reputation: 36139

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)

Upvotes: 2

Diego Freniche
Diego Freniche

Reputation: 5414

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

Upvotes: 2

Related Questions