FileManager.fileExistsAtPath 在 FileManager.removeItem 之前?

FileManager.fileExistsAtPath prior to FileManager.removeItem?

在 iOS 中,确保文件在删除之前存在是一种好习惯,还是继续尝试删除可能存在或可能不存在的文件并让错误发生在 catch 块中静默失败?

我正在遍历大量要删除的本地文件,其中大约 10% 可能不存在。

来自 apple documentationfileExistsAtPath: 方法:

Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It’s far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed.