Objective-C 学习笔记9 使用NSKeyedArchiver 归档
2013-01-26 09:28
246 查看
还是上一篇的例子
存
取
实例来源教材
存
// // main.m // sample005 // // Created by echoliu on 13-1-25. // Copyright (c) 2013年 echoliu. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { NSDictionary *glossary=[NSDictionary dictionaryWithObjectsAndKeys:@"a class",@"a", @"b class",@"b", @"c class",@"c",nil]; if ([NSKeyedArchiver archiveRootObject:glossary toFile: @"lossay.archiver"]==NO) { NSLog(@"save to file failed"); } } return 0; }
取
// // main.m // sample005 // // Created by echoliu on 13-1-25. // Copyright (c) 2013年 echoliu. All rights reserved. // #import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... //NSLog(@"Hello, World!"); /* NSDictionary *glossary=[NSDictionary dictionaryWithObjectsAndKeys:@"a class",@"a", @"b class",@"b", @"c class",@"c",nil]; if([glossary writeToFile:@"glossary" atomically:YES]==NO) NSLog(@"save to file failed"); */ /* NSDictionary *glossary ; glossary=[NSDictionary dictionaryWithContentsOfFile:@"glossary"]; for (NSString *str in glossary){ NSLog(@"%@ %@ ",str,[glossary objectForKey:str]); } */ /* NSDictionary *glossary=[NSDictionary dictionaryWithObjectsAndKeys:@"a class",@"a", @"b class",@"b", @"c class",@"c",nil]; if ([NSKeyedArchiver archiveRootObject:glossary toFile: @"lossay.archiver"]==NO) { NSLog(@"save to file failed"); } */ NSDictionary *glossary ; glossary=[NSKeyedUnarchiver unarchiveObjectWithFile:@"lossay.archiver"]; for (NSString *str in glossary){ NSLog(@"%@ %@ ",str,[glossary objectForKey:str]); } } return 0; }
实例来源教材
相关文章推荐
- Objective-C学习笔记(八)——高级跳转语句goto使用方法
- Objective-C学习笔记(十二)——switch多分支语句的使用
- Objective_C学习笔记(2)类的使用学习概要
- Objective-C 学习笔记之使用跨文件依赖关系
- 黑马程序员——Objective-C程序设计(第4版)学习笔记之19-归档——黑马 IOS 技术博客
- Objective-C 学习笔记12 文件使用结合NSData
- Objective-C学习笔记(九)——循环语句while的使用方法
- Objective-C 学习笔记13 目录的使用
- 【Objective_C学习笔记】Block的使用
- iOS学习笔记-034.数据的读取——NSKeyedArchiver归档(序列化)
- Objective-C学习笔记(十)——循环语句for和do-while的使用
- Objective-C学习笔记(十)——循环语句for和do-while的使用
- Objective-C 学习笔记8 归档
- Objective-c学习笔记(三)oc 多输入参数的方法及协议的使用及变量
- Objective-C 学习笔记11 文件使用
- 黑马程序员----Objective-C学习笔记之点语法的介绍和使用
- Objective-C 学习笔记10 NSCoding与归档
- Objective-C 学习笔记14 使用路径 NSPathUtilities.h
- 黑马程序员----Objective-C学习笔记之autorelease基本使用
- Programming in Objective-C 学习笔记09——对象复制与归档