如何将数据追加到 NSKeyedArchive?
我正在读取这样的文件:
NSData *data = [NSData dataWithContentsOfFile:myPath];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSData *imgData = [unarchiver decodeObjectForKey:@"myimage"];
if (imgData != nil) {
self.image = [[NSImage alloc]initWithData:imgData];
}else{
self.image = nil;
}
[unarchiver finishDecoding];
[unarchiver release];
我想做的是将键@“myimage”的图像数据附加到同一个文件(如果它不存在)。
该怎么办呢?
I'm reading a file like so:
NSData *data = [NSData dataWithContentsOfFile:myPath];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
NSData *imgData = [unarchiver decodeObjectForKey:@"myimage"];
if (imgData != nil) {
self.image = [[NSImage alloc]initWithData:imgData];
}else{
self.image = nil;
}
[unarchiver finishDecoding];
[unarchiver release];
What I'd like to do is to append image data for key @"myimage" to the same file if it doesn't exist.
How to go about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎没有办法“追加”到 NSKeyedArchive,所以我只是重新创建了它并添加了额外的数据并覆盖了原始文件。
It seems that there's no way to "append" to NSKeyedArchive, so I just re-created it with the extra data added and have written over the original file.