无法为类型为nsdictionary的类型的参数列表(对象:字符串?用于键[]字符串)调用初始化程序 [英] Cannot invoke initializer for type nsdictionary with an argument list of type(objects:String?for key [] string)
本文介绍了无法为类型为nsdictionary的类型的参数列表(对象:字符串?用于键[]字符串)调用初始化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将我的数据以键值对的形式添加到字典中.但是他们给了我上面提到的错误.这是我的代码
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"])
推荐答案
错误消息提示您将创建带有可选String
值的字典.
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"])
这篇关于无法为类型为nsdictionary的类型的参数列表(对象:字符串?用于键[]字符串)调用初始化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文