是否可以使用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用于执行此类更新操作。

但是,我没有找到一种方法,如何将数组NSManagedObjectIDInt64值数组应用于NSBatchUpdateRequest.

给定一个NSManagedObjectIDand数组Int64,是否可以用于NSBatchUpdateRequest在 CoreData 上执行更新?

以上是是否可以使用NSManagedObjectID数组执行NSBatchUpdateRequest?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>