How can I convert NSDictionary to NSData and vice versa?
来源:互联网 发布:linux中的grep命令 编辑:程序博客网 时间:2024/06/05 20:27
http://stackoverflow.com/questions/5513075/how-can-i-convert-nsdictionary-to-nsdata-and-vice-versa
NSDictionary -> NSData: NSMutableData *data = [[NSMutableData alloc] init]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data]; [archiver encodeObject:yourDictionary forKey:@"Some Key Value"]; [archiver finishEncoding]; [archiver release]; // Here, data holds the serialized version of your dictionary // do what you need to do with it before you: [data release];NSData -> NSDictionary NSData *data = [[NSMutableData alloc] initWithContentsOfFile:[self dataFilePath]]; NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; NSDictionary *myDictionary = [[unarchiver decodeObjectForKey:@"Some Key Value"] retain]; [unarchiver finishDecoding]; [unarchiver release]; [data release];You can do that with any class that conforms to NSCoding.
0 0
- How can I convert NSDictionary to NSData and vice versa?
- How can I convert NSDictionary to NSData and vice versa?
- How can I convert a QString to char* and vice versa ?
- How can I convert a QString to char* and vice versa?
- How to convert XSD to XML or vice versa
- Convert CGPoint/CGRect/CGSize to NSValue and vice versa
- python int convert string and vice versa
- wstring to string and vice versa
- c# - string to byte[] and vice versa
- How to Copy Archivelog Files From ASM to Filesystem and vice versa
- Enum to String and vice versa in C++
- R12 - GL / XLA / FAH - How to link GL data to the subledger data or vice versa
- Steps To Migrate-Move a Database From Non-ASM to ASM And Vice-Versa
- Steps To Migrate-Move a Database From Non-ASM to ASM And Vice-Versa
- Converting 11gR2 "Administrator" managed database to "Policy" managed and vice versa (文档 ID 1486772.
- How can I convert String to Int in C#?
- How can I convert printStackTrace message to a string?
- NSDictionary to NSData
- iOS 新特性分列式 之 iOS 5.x - 主要内容:自动引用计数、故事板、控件自定义呈现、容器视图控制器
- zend studio 改主题
- 一维byte数组旋转
- 安装MongoDB
- 保存图片到本地相册
- How can I convert NSDictionary to NSData and vice versa?
- HDU 4467 Graph(分块)
- android adb端口被占用解决方案
- spring中dataSource的org.apache.commons.pool.impl.GenericObjectPool异常
- java字符串切割
- MFC 学习之 鼠标移动到Toolbar按钮上显示提示信息(tooltip),状态栏也随之改变
- CSS设置字体
- UI第十七天:图⽚异步下载、KVO
- Eclipse常用的高效插件