2

Using NSFetchedResultsController and NSFetchRequest is it possible to setup a query that returns the highest value in each attribute.

For example:

Entity_001 A=F B=27 C=57
Entity_002 A=G B=23 C=98
Entity_003 A=X B=21 C=54
Entity_004 A=K B=11 C=27
Entity_005 A=R B=16 C=15

Result:

Entity_003 A=X B=21 C=54 // Biggest A
Entity_001 A=F B=27 C=57 // Biggest B
Entity_002 A=G B=23 C=98 // Biggest C

Essentially I have one data set and I need to pick out "the smallest", "the fastest" and "the heaviest" I could do it manually without using NSFetchedResultsController, or I guess I could use 3 NSFetchedResultsControllers and try and mesh the results back into a single data source. Any ideas would be very much appreciated ...

2 Answers 2

3
+50

I would do 3 different fetch requests to return the highest value for each particular request, and then merge the object IDs of each particular fetch request result into an array, and perform the NSFetchedResultsController fetch (to have notifications from changes) with a fetch request that looks for the IDs of the objects inside the array. Basically, it's 4 fetches. Three can be done in the background, one for the NSFetchedResultsController instance which will be done in the main thread.

Sign up to request clarification or add additional context in comments.

1 Comment

Much appreciated Sir, just what I was after.
1

Have you tried looking at KeyValue Coding?

1 Comment

This looks promising, but am I right in thinking this works directly on the managed object context and not via NSFetchedResultsController?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.