Swift中NSData与NSDictionary之间的相互转换
https://blog.csdn.net/ziyuzhiye/article/details/70056180
2017年04月11日 16:31:14 坤宇 阅读数:875
使用NSKeyedUnarchiver类来进行相互转换
1、NSDictionary转NSData
- var dictionaryExample : [String:AnyObject] = ["user":"UserName", "pass":"password", "token":"0123456789", "image":0]
- let dataExample : NSData = NSKeyedArchiver.archivedDataWithRootObject(dictionaryExample)
2、NSData转NSDictionary
let dictionary:NSDictionary = NSKeyedUnarchiver.unarchiveObjectWithData(dataExample)! as NSDictionary