IPhone: Why are mass inserts in basic data so slow?

So, I am making an iphone application that has only a thousand records that I read from an xml file into the main data. But inserting these records takes 10 seconds on the device. This is pretty funny.

The scheme is very simple, just one table. Ie, no relationship or anything else.

To understand what I mean, you can simply go to:
1. File β†’ New project β†’ Navigation application (make sure to use β€œUse basic data”)
2. Now inside RootViewController.m go to 'viewDidLoad' and in At the end of this method add:

   for (int n = 0; n < 1000; n++) [self insertNewObject];

And just run the application. Even in the simulator, it takes 5 seconds, and on devices - twice as slow. Any ideas?

+3
source share
1 answer

Arg ... I found a reason. I do not have to maintain context after every insert. My bad.

+2
source

Source: https://habr.com/ru/post/1767297/


All Articles