NSBatchRequest @CoreStore? #192

Closed
opened 2025-12-29 15:26:25 +01:00 by adam · 2 comments
Owner

Originally created by @shift00 on GitHub (Nov 29, 2017).

Hi,
can anyone tell me, does CoreStore supports batch requests? I need write multiple changes into database on existing data, but I can't find good solution for this problem.

For example NSBatchUpdateRequest seems like this:
let batchRequest = NSBatchUpdateRequest(entityName: "SomeEntity") batchRequest.propertiesToUpdate = ["status": PointType.new.rawValue] batchRequest.resultType = .updatedObjectIDsResultType

Originally created by @shift00 on GitHub (Nov 29, 2017). Hi, can anyone tell me, does CoreStore supports batch requests? I need write multiple changes into database on existing data, but I can't find good solution for this problem. For example NSBatchUpdateRequest seems like this: `let batchRequest = NSBatchUpdateRequest(entityName: "SomeEntity") batchRequest.propertiesToUpdate = ["status": PointType.new.rawValue] batchRequest.resultType = .updatedObjectIDsResultType`
adam closed this issue 2025-12-29 15:26:25 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Nov 29, 2017):

Hi, batch requests are currently not yet implemented, sorry.
You should still be able to do this manually within transactions:

CoreStore.perform(
    asynchronous: { (transaction) in

        let batchRequest = NSBatchUpdateRequest(
            entity: CoreStore.defaultStack.entityDescription(for: YourEntity.self)!
        )
        batchRequest.propertiesToUpdate = ["status": PointType.new.rawValue]
        batchRequest.resultType = .updatedObjectIDsResultType
        try transaction.unsafeContext().execute(batchRequest)
    },
    completion: { _ in /* ... */ }
)
@JohnEstropia commented on GitHub (Nov 29, 2017): Hi, batch requests are currently not yet implemented, sorry. You should still be able to do this manually within transactions: ```swift CoreStore.perform( asynchronous: { (transaction) in let batchRequest = NSBatchUpdateRequest( entity: CoreStore.defaultStack.entityDescription(for: YourEntity.self)! ) batchRequest.propertiesToUpdate = ["status": PointType.new.rawValue] batchRequest.resultType = .updatedObjectIDsResultType try transaction.unsafeContext().execute(batchRequest) }, completion: { _ in /* ... */ } ) ```
Author
Owner

@shift00 commented on GitHub (Nov 30, 2017):

It's working! Thanks.

@shift00 commented on GitHub (Nov 30, 2017): It's working! Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#192