iOS CoreData 批量插入? [英] iOS CoreData batch insert?

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

问题描述

在我的 iPhone 应用程序中,我需要将 ~2000 条记录插入到 Core Data 中,然后用户才能使用该应用程序的任何功能.我正在将记录从本地 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).

Core 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天全站免登陆