What format does NSKeyedArchiver save?

穿精又带淫゛_ 提交于 2019-12-21 10:16:23

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/2447886/what-format-does-nskeyedarchiver-save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!