'How I can delete the children of folder using CoreData?
func deleteFolder(indexSet : IndexSet) {
for folder in indexSet {
let folderToDelete = folders[folder]
do {
coreDataService.context.delete(folderToDelete)
try coreDataService.save()
getFolders()
} catch {
print("Error = \(error)")
}
}
}
func deleteContent(indexSet : IndexSet) {
for content in indexSet {
let contentToDelete = contents[content]
do {
coreDataService.context.delete(contentToDelete)
try coreDataService.save()
getContetns()
} catch {
print("Error = \(error)")
}
}
}
I am trying to do data management by Coredata. There is 2 models, a folder and contents. the folder can have many contents, but the content is able to have only one folder.
I tried to delete a folder with onDelete using indexSet and succeeded with the function in my code. but I can't delete a content in a folder with that.
Could you let me know how I can do that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
