本文共 602 字,大约阅读时间需要 2 分钟。
NSKeyedArchiver在linux的实现默认的格式是二进制:
NSArray *ary = @[@"hello",@"world",@"!!!",@11];[NSKeyedArchiver archiveRootObject:ary toFile:@"./foo.dat"];
我们还可以选择XML格式:
NSMutableData *data = [NSMutableData data]; NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];//The available formats are NSPropertyListXMLFormat_v1_0 and NSPropertyListBinaryFormat_v1_0 archiver.outputFormat = NSPropertyListXMLFormat_v1_0; [archiver encodeObject:ary forKey:@"root"]; [archiver finishEncoding]; [data writeToFile:@"./foo.dat" atomically:YES];
转载地址:http://eyica.baihongyu.com/