//
// main.m
// OC语言学习
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
/*
在OC语言中,归档是一个过程,即用某种格式来保存一个或多个对象,以便以后还原这些对象。
通常,这个过程包括将多个对象写入文件中,以便以后读取该对象。
*/
@autoreleasepool {
//使用XML属性列表进行归档
NSDictionary *gloss = [NSDictionary dictionaryWithObjectsAndKeys:@"A class",@"ka",@"B class",@"kb",@"C calss",@"kc", nil];
if ([gloss writeToFile:@"gloss" atomically:YES] == NO) {
NSLog(@"保存失败");
}
/*
writeToFile:atomically:消息发送给字典对象gloss,使字典以属性列表的形式写入文件gloss中。
atomically参数设为YES,表示希望首先将字典写入临时备份文件中,并且一旦成功,将把最终数据转移到名为gloss的制定文件中。
*/
/*
当根据字典创建属性列表时,字典中的键必须全都是NSString对象。
数组中的元素或字典中的值可以是 NSString、NSArray、NSDictionary、NSData、NSDate、NSNumber对象。
*/
/*
若要将文件中的XML属性列表读入你的程序
dictionaryWithContentsOfFile:
arrayWithContentsOfFile:
要读取数据
dataWithContentsOfFile:
要读取字符串对象
stringWithContentsOfFile:
*/
gloss = [NSDictionary dictionaryWithContentsOfFile:@"gloss"];
for (NSString *key in gloss) {
NSLog(@"%@: %@",key,[gloss objectForKey:key]);
}
}
return 0;
}
归档—使用XML属性列表进行归档
最新推荐文章于 2018-09-04 16:56:19 发布