0

For example

NSString *path = @"XXX";
id obj = [NSKeyedUnarchiver unarchiveObjectWithFile:path];

and somewhere else is going to delete this file by removeItemAtPath, whether it is safe to do that? as I know, if I write an object to the file with archiver and I modify that object meanwhile, it will cause crash, but I don't understand the essence of the that, so I wonder what will happen if I operate like this.

4

1 回答 1

2

不,它不会崩溃。在没有进程打开文件之前,不会真正删除文件。只要取消存档程序打开文件以供阅读,您就可以尝试删除所有您想要的内容而不会出现问题。解压完成并关闭文件后,操作系统将实际删除该文件。

这对真正发生的事情有点过于简单,但它应该足以解决您的问题。

有关更详细的说明,请参阅UNIX 命令 mv 和 rm 如何处理打开的文件?和其他类似的问题。iOS 是 Unix 类型的操作系统,因此当您阅读该问题和接受的答案时,所有提到 Unix 的内容都适用于 iOS。如果您不熟悉 Unix,rm请使用删除 Unix 文件的命令。

于 2015-12-10T03:07:23.153 回答