开发者

Core Data: force one attribute to load before others

I have some transient attributes in my Entity that are derived from one other transient attribute (call is X). When I do a fetch, it seems to try to load all attributes in no particular order, so if X is taking some time to calculate, the other derived attributes try to use X and it's null so it causes issues.

Is there any way to force Core Data to ensure loading one attribute before other attributes can read from it? Or force the ot开发者_开发问答her attributes to reload once attribute X has done loading? Any other technique anyone would recommend? I'm using this in an iOS tableView backed by an NSFetchedResultsController.


No you can't force attributes to "load" in order because attributes don't load. You are initializing objects here and not reading cells in a procedural database.

I'm going to guess that your trying to calculate some value based on the attributes or counts of external objects. If so, then you can get serious slow downs while the other objects are faulted in so that their values can be accessed.

If so, then you've got a data model design problem. I've never seen a transient value so complex that its calculation impaired operation. You probably need to break it apart or even move it to its own object.

E.g Suppose you've got a data model that simulates a group of people with Person objects. You want some behavior of each Person object to change depending on how many people their are. So, when there are less than five each person does "X" if there are 6 to 10 you do "Y" and so on.

In that circumstance, it would be best to create a second entity related to all the Person objects that tracks the number of Person objects total. Then getting the count of all Person objects or the collective sum of one of the Person entity attributes becomes fast and trivial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜