Kodeco Forums

Video Tutorial: Beginning Core Data Part 5: Editing & Deleting Data

Learn how to edit and delete objects in Core Data and how to handle relationships when deleting objects.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3813-beginning-core-data/lessons/6

I am trying to do the update request with following code. But it is not being updated. What i am doing wrong?

let deviceUpdateRequest = NSBatchUpdateRequest(
entityName: “Device”)
deviceUpdateRequest.resultType = .UpdatedObjectIDsResultType
deviceUpdateRequest.predicate = nil
deviceUpdateRequest.propertiesToUpdate = [“deviceType”:“iphone”]

do {
    let deviceResult =
        try managedObjectContext.executeRequest(deviceUpdateRequest)
            as! NSBatchUpdateResult
    let alert = UIAlertController(title: "Batch Update Succeeded",message: "\(deviceResult.result!.count!) device records updated.",
                                  preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "OK",
        style: .Cancel, handler: nil))
    presentViewController(alert, animated: true, completion: nil)
} catch {
    let alert = UIAlertController(title: "Batch Update Failed",
                                  message: "There was an error with the batch update.",
                                  preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "OK",
        style: .Cancel, handler: nil))
    presentViewController(alert, animated: true, completion: nil)
}

:slight_smile: Hi … you should check challenge documentation, because there’re many mistakes:

  1. for header there must be set up reuse identifier “Header”;
  2. there’re no such function stringFromEyeColor() → In completed project for this part there’re such a function, but it doesn’t work:

fatal error: unexpectedly found nil while unwrapping an Optional value

Hi, I have simple question, how to make auto increment field in core data