我正在尝试进行批量更新,但我没有得到异常,但它告诉我0条记录已更新。如果我运行以下代码
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")
然后我得到这个输出:
设置0个对象完成(应为6470)
我找到了6470个订单
所以它肯定会看到我期望它的对象,但它不会更新它们中的任何一个。我在这里做错了什么?
如果它有任何区别,那就是在子上下文中