Reputation: 1891
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
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
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
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