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