本文介绍了writeToFile如何判断它何时完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一些数据到我的文档目录,我想知道是否有办法告诉我的writeToFile方法何时完成,我创建的文件是否已完全创建。在此先感谢这里是我正在调用的方法我正在寻找一种方式,它是委托方法还是其它方式告诉它何时完成。

I'm doing some writing of data to my documents directory and I was wondering if there is a way to tell when my writeToFile method completes and the file I am creating has be fully created. Thanks in advance here is the method I am calling I am just looking for a way wether it is a delegate method or some other way to tell when this completes.

[imageData writeToFile:fullPathToFile atomically:YES];

Nick

推荐答案

方法 writeToFile:atomically 是同步。它将写入文件,然后返回 YES NO ,具体取决于文件是否成功写入。

The method writeToFile:atomically is "synchronous". It will write the file and then return YES or NO depending on wether the file was successfully written or not.

这意味着一旦方法返回,操作就完成了。

That means that the operation is complete as soon as the method returns.

BOOL success = [imageData writeToFile:fullPathToFile atomically:YES];
// Now, the operation is complete
// success indicates whether the file was successfully written or not

这篇关于writeToFile如何判断它何时完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-14 21:14