ich müde, dieses Problem zu lösen, aber wenn es entfernen es anderen Foto-Pfad entfernen, weil ich .lastPathComponent verwenden Wie PrepareForDeletion verwenden, um Foto in CoreData Swift zu löschen?
override func prepareForDeletion() {
super.prepareForDeletion()
if filePath != nil {
let fileName = (filePath! as NSString).lastPathComponent
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentationDirectory, .UserDomainMask, true)[0]
let pathArray = [dirPath, fileName]
let fileURL = NSURL.fileURLWithPathComponents(pathArray)!
do {
try NSFileManager.defaultManager().removeItemAtURL(fileURL)
try NSFileManager.defaultManager().removeItemAtPath(fileName)
} catch let error as NSError {
print("Error from prepareForDeletion - \(error)")
}
} else {
print("filepath is empty")
}
}
ich es bekam
die richtige filePath erkannt, dass die richtige Antwort ist
override func prepareForDeletion() {
super.prepareForDeletion()
if filePath != nil {
if let imagePath = self.filePath {
do {
try NSFileManager.defaultManager().removeItemAtPath(imagePath)
} catch let error as NSError {
print("Error from prepareForDeletion - \(error)")
}
}
} else {
print("filepath is empty")
}
}
i entfernen es i hinzugefügt wurde, als ich –