WWDC22 SALE: Save 50% on all my Swift books and bundles! >>

Marrying multiple http requests with Core Data

Forums > iOS


Currently I'm working with an API that (for particular data) doesn't support multiget. So for example, I need to make around 500 requests to get all information about objects tied to my account (amount depending on a user). From that I need to create entities (or update existing ones if changed) in Core Data, to have a local copy.

Since I want to download the data concurrently I don't want to use main NSManagedObjectContext each time data is downloaded or spawn a background context each time I receive response (this would probably create a lot of threads).

How would you best tackle this task? Use OperationQueue/BlockOperation to download the data and when everything is done, spawn a background context (via performBackgroundTask) and store everything to Core Data in one blow (to not cause any merge conflicts too)? Or maybe use DispatchQueue with groups? Or maybe something else?



Save 50% in my Black Friday sale.

SAVE 50% To celebrate WWDC22, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.

Save 50% on all our books and bundles!

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.