0

I'm trying to do a batch update and I'm not getting an exception, but it's telling me 0 records are updated. If I run the following code

let request = NSBatchUpdateRequest(entityName: "Order")
request.predicate = NSPredicate(format: "sql_ident IN %@", completed)
request.propertiesToUpdate = ["complete" : true]
request.resultType = .UpdatedObjectsCountResultType

do {                
    let res = try moc.executeRequest(request) as! NSBatchUpdateResult
    print("Set \(res.result!) objects to complete (should be \(completed.count))")
} catch let error as NSError {
    print("Error: \(error.localizedDescription)")
}                   

let r = NSFetchRequest(entityName: "Order")
r.predicate = NSPredicate(format: "sql_ident IN %@", completed)
let count = moc.countForFetchRequest(r, error: nil)
print("I found \(count) orders")

Then I get this output:
Set 0 objects to complete (should be 6470)
I found 6470 orders

So it's definitely seeing the objects I expect it to, but it's not updating any of them. What am I doing wrong here?

If it makes any difference, this is in a child context

Gargoyle
  • 9,590
  • 16
  • 80
  • 145

0 Answers0