将NSDictionary转换为Swift Dictionary [英] Convert NSDictionary to Swift Dictionary
本文介绍了将NSDictionary转换为Swift Dictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< key,value>
? 或
有没有办法将其转换为Swift字典而不是NSDictionary?
let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData,options:nil,error:& error)as NSDictionary
解决方案
使用:
让jsonDic = NSJSONSerialization.JSONObjectWithData(jsonData,options:NSJSONReadingOptions.MutableContainers,error:& error)as Dictionary< String,AnyObject> ;;
Now I know that when swift compiles it just makes a NSDictionary, but the NSDictionary and Swift dictionaries have different syntax. Is there a way (through a loop or something) to convert a NSDictionary to a swift dictionary of the same type for <key, value>
?
OR
Is there a way to convert this to a Swift dictionary instead of NSDictionary?
let jsonDict = NSJSONSerialization.JSONObjectWithData(jsonData, options: nil, error: &error) as NSDictionary
解决方案
use:
let jsonDic = NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers, error: &error) as Dictionary<String, AnyObject>;
这篇关于将NSDictionary转换为Swift Dictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文