Andrew21111
Andrew21111

Reputation: 908

Swift 3 - Trying to cast a dictionary to CFDictionary

When I'm trying to create an array as a CFDictionary, I'm getting an error (shown bellow).

This is the code:

let attrs = [kCVPixelBufferCGImageCompatibilityKey:kCFBooleanTrue,  kCVPixelBufferCGBitmapContextCompatibilityKey:kCFBooleanTrue] as CFDictionary

But the weird thing is that I'm using the same line of code in another project, without receiving any errors. What does the error mean?

Error: Contextual type 'CFDictionary' cannot be used with dictionary literal

Upvotes: 1

Views: 857

Answers (1)

CodeChanger
CodeChanger

Reputation: 8351

You can use below code to convert the dictionary to CFDictionary as mention below:

let attrs = [kCVPixelBufferCGImageCompatibilityKey as String :kCFBooleanTrue,
             kCVPixelBufferCGBitmapContextCompatibilityKey as String:kCFBooleanTrue] as
        CFDictionary

Hope This will helps

Upvotes: 4

Related Questions