Swift 2: Type of expression is ambiguous without more context, for a dictionary

陌路散爱 提交于 2019-12-23 06:08:47

问题


Why is the compiler throwing an error for the following code that attempts to create a dictionary? How would you fix this code?

let options = [
  kCVPixelBufferCGImageCompatibilityKey: true,
  kCVPixelBufferCGBitmapContextCompatibilityKey: true]

I've looked through all of the other related questions with this same error and have not been able to find a solution.


回答1:


How about

let options : [NSObject : AnyObject] = [
    kCVPixelBufferCGImageCompatibilityKey: true,
    kCVPixelBufferCGBitmapContextCompatibilityKey: true]

[NSObject : AnyObject] is the equivalent to NSDictionary in Objective-C. The library you're using requires it to be of this type.



来源:https://stackoverflow.com/questions/33246582/swift-2-type-of-expression-is-ambiguous-without-more-context-for-a-dictionary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!