CoreData工作缓慢,因为有很多对象。如何优化呢? [英] CoreData works slowly because there are a lot of objects. How can I optimize it?

查看:319
本文介绍了CoreData工作缓慢,因为有很多对象。如何优化呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有entity1,其中包含entity2的NSOrderedSet。 Entity2有100个字符串字段。



我在2-3小时内每/秒创建一个entity2的managedObject,并将其添加到entity1。我可以创建一个entity1每天。我每天都这样做!因此在一周内,我的CoreDate数据库将包含(7 * 3或4)21个或28个managedObjects的entity1其中包含entity2的(21 * 2或3 * 3600)226800个对象。



每次使用coreData的操作(插入,删除,保存)



如何解决此问题?

解决方案

应用程序将永远占用用户的存储越来越多?听起来像是一个很好的方式被删除。



如果你在处理大量的数据,并希望快速查询结果,使您的应用程序是响应,你应该使用并发核心数据,所以实际的数据工作是在另一个线程完成,一旦一旦加载,你可以更新你的UI。现代的做法是使用并发类型创建MOC并使用父/子上下文,或者使用iOS 8中引入的新的异步获取。


I have entity1 which contains NSOrderedSet of entity2. Entity2 has 100 string fields.

I create managedObject of entity2 per/sec during 2-3 hours and add it to entity1. I can create some entity1 per/day. I do it everyday! I can't create them rarely (It is required).

So in one week my CoreDate dataBase will contain (7 * 3 or 4) 21 or 28 managedObjects of entity1 which contains (21 * 2 or 3 * 3600) 226800 objects of entity2.

And each next operation (insert, remove, save) with coreData will go more slowly than before.

How can I resolve this problem?

解决方案

So your app is going to take up more and more of the user's storage forever? Sounds like a good way to get deleted.

If you're dealing with lots of data and want fast query results so that your app is responsive, you should use concurrency with Core Data so the actual data work is done on another thread, and once everything is loaded you can update your UI. The modern way to do that is a combination of creating MOCs with a Concurrency Type and using parent/child contexts, or using the new asynchronous fetching introduced in iOS 8.

这篇关于CoreData工作缓慢,因为有很多对象。如何优化呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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