small medium large xlarge

Back to: All Forums  Core Data
01 Dec 2009, 17:05
Greg Robertson (21 posts)

I would like to be able fetch objects that have been sorted based on a dynamic value that would not be know until runtime. The value not know until runtime would be the current date.

For example if I have a database of all items I wish to or have purchase/d which includes attributes such as: -name (name of item) -cost (cost of item) -anticipatedDate (used for proposed purchase date of item) -actualDate (date item was purchased)

And I would like to fetch (using NSFetchedResultsController) the objects in three distinct groupings: A. items that have been purchased. B. items not purchased that were proposed to be purchased before today. C. items not purchased that are proposed to be purchased after today.

Because of the way NSFetchedResultsController works it would appear that I would need to create an attribute that would calculate on the fly (or immediately before the comparison) to indicate condition A, B or C noted above.

Not necessarily looking for code but for how conceptually I should go about doing the sort.



10 Dec 2009, 08:06
Marcus S. Zarra (284 posts)

I would set up a transient value that is populated on fetch which stores the A/B/C state. Then you can retrieve all of the values at once and sort based on that transient value.

You must be logged in to comment