0

我一直在尝试使用 NSMutableArray 的 writeToFile:atomically:

但有人向我指出这种方法是错误的:即iPhone / Objective-C: NSMutableArray writeToFile 不会写入文件。总是返回 NO

看来我将不得不阅读上述链接中的一个答案中提到的存档指南。

有人愿意分享(或指向我)一些帮助我完成这项任务的代码吗?

4

1 回答 1

1

您提到的方法在写出文件之前递归地验证所有包含的对象都是属性列表对象。

尝试这个:

for (UIImage *image in arrayWithImages) {
    NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", @"nameOfTheImage.png"]];
    UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
}

也许您可以使用[UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES];将图像编写为 jpeg。

于 2011-08-23T13:22:36.810 回答