核心数据:观察特定类型实体的所有变化 [英] Core Data: Observing all changes on Entity of certain type

查看:90
本文介绍了核心数据:观察特定类型实体的所有变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在添加/更改/删除某种类型的实体时收到通知。我知道可以通过向 managedObjectContext 添加观察者来实现,但是随后我必须搜索返回的三个集合,以查看它们是否包含该类型的对象。我可以使用 filteredSetUsingPredicate ,但每次更改一次,执行三次O(n)操作似乎效率不高。还有另一种更有效的方法来实现此目的吗?

I would like to be notified whenever an entity of a certain type is added/changed/removed. I know that this is possible by adding an observer to the managedObjectContext, but then I have to search the three sets that are returned to see if they contain an object of that type. I could use filteredSetUsingPredicate, but it seems inefficient to do an O(n) operation three times every time there is a change. Is there another more efficient way to accomplish this?

推荐答案

它似乎效率低下吗?根据什么测试和观察?您如何看待NSArrayController的工作原理(提示-阅读可可绑定)? :-)当然,使用SQLite存储类型时,您会在数据库中进行访存过滤,但是对对象的内存中更改又如何呢?

It seems inefficient? Based on what testing and observation? How do you think NSArrayController works (hint - read up on Cocoa Bindings)? :-) Sure, with a SQLite store type you get in-database filtering for fetches but what about in-memory changes to the objects?

如果我在您的位置,我将其连接起来并对其进行性能测试,并以我认为是现实生活中的用户可能遇到的合理的最坏情况。

If I were in your position, I'd wire it up and performance test it with what I imagine is a reasonable worst-case scenario that a real-life user is likely to encounter.

发现确实确实缺乏性能,最好是发布一个单独的问题来描述您的数据模型,观察给定实体的所有实例的所有变化的原因以及仪器说性能下降的位置。

If you find performance is indeed lacking, it's best you post a separate question describing your data model, the reasons you need to observe all changes to all instances of a given entity, and where Instruments says the performance sink is happening.

这篇关于核心数据:观察特定类型实体的所有变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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