Good day to all, night.
I'm trying to learn CoreData and tritely can't figure out how to check and update the data.
This is my code, but how to update it :(
// Проверяем добавленн уже в список продукт или нет // Обновляем CoreData со ячейкой let row = self.test[indexPath.row].valueForKey("productName")! let managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext let fetchRequest = NSFetchRequest(entityName: "Products") if let fetchResults = try!managedObjectContext.executeFetchRequest(fetchRequest) as? [NSManagedObject] { for i in 0..<fetchResults.count { if String(fetchResults[i].valueForKey("productName")!) == row as! String { // Обновляем наши данные // Если у нас false 0 то устанавливаем true 1, и все наоборот if (fetchResults[i].valueForKey("addedToList")!.boolValue == true) { managedObjectContext.setValue(0, forKey: "addedToList") } else { managedObjectContext.setValue(1, forKey: "addedToList") } try!managedObjectContext.save() self.tableView.reloadData() } } }