我有一个收藏按钮,当点击时会将特定角色的图像添加到CoreData中。
@IBAction func favButtonClicked(_ sender: UIButton) {
if sender.isSelected != true {
saveFav()
}
}
func saveFav() {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let newFav = NSEntityDescription.insertNewObject(forEntityName: "Favorite", into: context)
newFav.setValue((figure?.image)!, forKey: "favFig")
do {
try context.save()
print("Saved!")
} catch {
//Process Error
}
}
我的问题是,当再次点击按钮时,如何从CoreData中删除那张图片?