Yorgunum bu sorunu çözmek için ama ben .lastPathComponent CoreData swift'de fotoğrafı silmek için prepareForDeletion nasıl kullanılır?
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")
}
}
Doğru filePath doğru cevap
olduğunu tespitgot kullanmak çünkü diğer fotoğraf yolunu kaldırmak kaldırdığınızda
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 içeri mağazayı olmamalı sınıf Foto –