您可以使用FileManager类来判断文件是否存在,并使用removeItem(at:)方法来删除文件。以下是一个示例代码:

import Foundation

// 获取文件的完整路径
let personsArrPath = "路径/personsArrPath"

// 创建文件管理器实例
let fileManager = FileManager.default

// 判断文件是否存在
if fileManager.fileExists(atPath: personsArrPath) {
    do {
        // 删除文件
        try fileManager.removeItem(atPath: personsArrPath)
        print("文件删除成功!")
    } catch {
        print("删除文件失败:\(error)")
    }
} else {
    print("文件不存在!")
}

请确保将路径/personsArrPath替换为您实际的文件路径

ios 判断personsArrPath文件路径是否存在数据如果存在那么删除

原文地址: https://www.cveoy.top/t/topic/ij8F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录