是否可以使用NSManagedObjectID数组执行NSBatchUpdateRequest?
目前,我通过以下代码执行多个更新操作。
func updateOrders(_ updates : [(objectID: NSManagedObjectID, order: Int64)]) {
if updates.isEmpty {
return
}
let coreDataStack = CoreDataStack.INSTANCE
let backgroundContext = coreDataStack.backgroundContext
backgroundContext.perform {
for update in updates {
let objectID = update.objectID
let order = update.order
let nsPlainNote = try! backgroundContext.existingObject(with: objectID) as! NSPlainNote
nsPlainNote.order = order
}
RepositoryUtils.saveContextIfPossible(backgroundContext)
}
}
既然我愿意
- 使更新操作运行得更快
- 避免
NSFetchedResultController被通知的委托
我想NSBatchUpdateRequest用于执行此类更新操作。
但是,我没有找到一种方法,如何将数组NSManagedObjectID和Int64值数组应用于NSBatchUpdateRequest.
给定一个NSManagedObjectIDand数组Int64,是否可以用于NSBatchUpdateRequest在 CoreData 上执行更新?
THE END
二维码