Cannot invoke initializer for type nsdictionary with an argument list of type(objects:String?for key [] string)

眉间皱痕 提交于 2020-01-03 06:32:10

问题


I want to add my data in dictionary in form of key value pair. But They give me error mentioned above. Here is my Code

let dictionary = NSDictionary(objects: [getStringAt(selectStmt, column: 0), getStringAt(selectStmt, column: 1)], forKeys: ["username", "image"])

回答1:


The error message says that you're going to create an dictionary with optional String values.

Since all values in a dictionary must be non-optional you have to unwrap them.

let dictionary = NSDictionary(objects: [getStringAt(selectStmt, column: 0)!, getStringAt(selectStmt, column: 1)!], forKeys: ["username", "image"])


来源:https://stackoverflow.com/questions/33338463/cannot-invoke-initializer-for-type-nsdictionary-with-an-argument-list-of-typeob

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