gpt4 book ai didi

ios - FileManager.fileExistsAtPath 在 FileManager.removeItem 之前?

转载 作者:行者123 更新时间:2023-11-28 18:15:42 25 4
gpt4 key购买 nike

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

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

最佳答案

来自apple documentation对于 fileExistsAtPath: 方法:

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.

关于ios - FileManager.fileExistsAtPath 在 FileManager.removeItem 之前?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40984772/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com