问题描述
当我使用NSKeyedArchiver是写一个* .plist的数据,我看到一些例子,人们有输出文件下来作为* .txt或甚至没有扩展名?
When I use NSKeyedArchiver is the data that is written a *.plist, I have seen some examples where people have the output file down as *.txt or even without an extension at all?
-(void)saveCore {
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:reactorCore forKey:@"CORE"];
[archiver finishEncoding];
[data writeToFile:[self dataFilePath] atomically:YES];
[data release];
[archiver release];
}
gary
推荐答案
您可以使用任何您想要的文件扩展名。它与NSKeyedArchiver使用的实际文件格式完全无关。默认情况下,归档将以二进制形式,但如果您将归档程序的 outputFormat
属性设置为 NSPropertyListXMLFormat_v1_0
编写一个XML plist。当你这样做,你应该给你的文件一个.plist或.xml扩展名。
You can use any file extension you want. It is completely unrelated to the actual file format NSKeyedArchiver uses. By default, the archive will be in binary form, but if you set the archiver's outputFormat
property to NSPropertyListXMLFormat_v1_0
, it will write an XML plist. And when you do that, you should probably give your file a .plist or .xml extension.
这篇关于NSKeyedArchiver保存什么格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!