问题
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