iOS CoreData批处理插入? [英] iOS CoreData batch insert?

查看:109
本文介绍了iOS CoreData批处理插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPhone应用程序中,我需要在Core Data中插入〜2000条记录,然后用户才能使用应用程序的任何功能。我从本地JSON文件加载记录到CoreData。此过程需要很长时间(2.5+分钟),但只需要发生一次(或每打开〜10个应用程序打开以获取更新的数据)。

In my iPhone application, i need to insert ~2000 records into Core Data before the user can use any features of the application. I am loading the records into CoreData from a local JSON file. This process is taking a long time(2.5+ minutes), but only needs to happen once(or every ~10 application opens to get updated data).

核心数据的批处理插入?如何加速此插入过程?

Is there a batch insert for Core Data? How can i speed up this insert process?

如果我无法使用Core Data加快速度,还有哪些其他推荐的选项?

If i can't speed it up using Core Data, what are the other recommended options?

推荐答案

查看从核心数据编程指南中有效导入数据一章。

我目前遇到的问题与您一样,只有我插入10000个对象,它需要大约30秒,这对我来说仍然很慢。我对插入到上下文中的每1000个托管对象执行[managedObjectContext save](换句话说,我的批量大小为1000)。我已经尝试了30种不同的批次大小(从1到10000),而1000似乎是我的情况下的最佳值。

I'm currently having the same problems as you, only I'm inserting 10000 objects and it takes around 30s, which is still slow for me. I'm doing a [managedObjectContext save] on every 1000 managed objects inserted into the context (in other words, my batch size is 1000). I've experimented with 30 different batch sizes (from 1 to 10000), and 1000 seems to be the optimum value in my case.

这篇关于iOS CoreData批处理插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆