Transaction/Commit on Core Data, is it possible?

Asked

Viewed 72 times

2

There is the concept of Transaction and Commit in Core Data?

I have a database in the app that is fed by an external file, but it is a lot of data and the application takes around 2 minutes to perform this import so I need to run it in the background.

Is there any way to start a transaction when I start importing (delete all old data and insert new data) and commit when finished?

Since it is possible to use the app while the import is being performed, it is possible that access to some data has been deleted and this crashes the app (so I need to perform in a transaction).

An alternative I thought is to create a database cache if it is not possible to do Transaction and Commit.

  • Kick: the beginUndoGrouping and endUndoGrouping methods would not solve your problem? (the undo method serves to actually rollback in case of failure.) http://stackoverflow.com/questions/9733233/ios-core-data-how-to-implement-the-sql-transaction-function

  • Which method do you use to copy the data, GET or POST? if possible by code.

  • @Williammonteiro in what the method used matters? My problem is only with Core Data, but from what I saw here just save the context only after finishing the full import and not every Insert/delete. I’ll test that yet and if you solve I’ll close the question.

1 answer

1


There is no such thinking in Core Data.

When you fetch the data and turn it into objects, even after making changes to those objects, you’re not necessarily saving them. Only the insertion/editing of data is done, if called the save method of the core data. This is because all these objects are only in the application memory and are only returned to the base using the method -save of core data.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.