Convert from NSDictionary to [String:Any?]

廉价感情. 提交于 2019-12-10 15:55:50

问题


I am using xmartlabs/Eureka to build an app with a dynamic form.

In order to fill the form I have to use setValues(values: [String: Any?]).

But I have the form values in an NSDictionary variable and I cannot cast it to [String:Any?].

Is there a way to convert an NSDictionary to [String:Any?] ?


回答1:


Hope this helps:

let dict = NSDictionary()
var anyDict = [String: Any?]()

for (value, key) in dict {
    anyDict[key as! String] = value
}



回答2:


Just an example:

if let content = data["data"] as? [String:AnyObject] {
    print(content)
}

The data is a JSON object here. Use it accordingly.



来源:https://stackoverflow.com/questions/37810789/convert-from-nsdictionary-to-stringany

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