【发布时间】:2017-02-25 08:29:16
【问题描述】:
我在这里做错了什么? 我正在尝试删除一个给定的文件,而我看到的所有documentation 和examples 都让它看起来应该可以工作。
func deleteThisFile(fileToDelete: String) {
let tempLocalDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
do {
let directoryContents = try FileManager.default.contentsOfDirectory(at: tempLocalDir!, includingPropertiesForKeys: nil, options: [])
let tempList = directoryContents.filter{ $0.absoluteString.contains(fileToDelete) }
//tried these things:
try FileManager.removeItem(tempList.first) // Argument labels '(_:)' do not match any available overloads
/*
* try FileManager.removeItem(at: tempList.first!) // Ambiguous reference to member 'removeItem(atPath:)'
*
* try FileManager.removeItem(atPath: (tempList.first?.absoluteString)!) // Ambiguous reference to member 'removeItem(atPath:)'
*/
} catch let error as NSError {
print(error.localizedDescription)
}
}
未注释的是 FileManager.removeItem 在我键入时自动提示的内容。
任何关于错误的澄清都会很棒
【问题讨论】: