Once created, the What you need to keep in mind is that the changes happen directly in the Persistent Store.They are not automatically reflected in the Managed Object Context.Let’s build an example to understand better how batch updates work in Core Data for i OS 8. Let’s add first a method to the View Controller class to perform the classic fetch-update-save.
Let’s now overwrite the flag to switch between the new batch update approach (lines 2-6) or the legacy one (line 7). Then, I define the property I want to update (line 3).I create a dictionary with the keys representing the properties I want to updates and the values representing the new values of each property.After that, you had to touch every managed object and update the properties with the new values.Finally, you had to save the results back into the Persistent Store. However, in real applications the update of a large number of objects requires quite long processing time.First, let’s compare the processing time of the two approaches.
I am going to run this code on an i Phone 5s and use the 100 thousand records previously created.
application is the configuration of the model layer.
Core Data operates with a mutable model layer, where objects are always passed by reference and the same instance is modified when an object is edited. Instead, a view model (or some sort of token object) should be used to mimic (or act as a placeholder for) the data that will be displayed in the collection view.
There is still some work you have to do to keep in sync the UI and your data, but the separation between the managed object context and the persistent store coordinator makes easier to keep the UI responsive. The batch request is composed of an entity (the entity containing the property or properties you want to update) and a predicate to define a subset of data you want to update.
Additionally, the processing performance and memory usage of the batch updates are really impressive. Eventually, you can also define a dictionary containing the properties you want to update and their new values.
This will allow you to modify one or more properties of your entities with no need of loading the data into the Managed Object Context.