2
votes

Is it safe to use the viewContext to save into the persistent store if I have large amounts of data? For example, I have 1000 records on my temporary background context which is a child of the viewContext of the NSPersistentContainer. Once I am done saving all 1000 records in the bg context, I want to save it using the viewContext to persist on the database. Is this the right approach or I should create a background context for saving to the persistent store?

1
You should use viewContext for UI and newBackgroundContext for writing data to disk. - Parag Bafna

1 Answers

0
votes

Generally, I would use a background context for saving large amounts of data and let the main context pick up the changes from the persistent store.

I try use the main context as a read only context as much as possible in apps and use background or child contexts for saving and editing.