views:

37

answers:

1

From the docs:

To summarize, though, if you execute a fetch directly, you should typically not add Objective-C-based predicates or sort descriptors to the fetch request. Instead you should apply these to the results of the fetch. If you use an array controller, you may need to subclass NSArrayController so you can have it not pass the sort descriptors to the persistent store and instead do the sorting after your data has been fetched.

I don't get it. What's wrong with using them on fetch requests? Isn't it stupid to get back a whole big bunch of managed objects just to pick out a 1% of them in memory, leaving 99% garbage floating around? Isn't it much better to only fetch from the persistent store what you really need, in the order you need it? Probably I did get that wrong...

+1  A: 

The documentation refers to Objective-C-based predicates or sort descriptors. This is NOT the same thing as a standard predicate or sort descriptor you see in the example available in the same page of the documentation you are quoting.

For instance, using

+ (NSPredicate *)predicateWithBlock:(BOOL (^)(id evaluatedObject, NSDictionary *bindings))block;

to build a predicate allows you using Objective-C to implement the block used to select the objects. Since the complexity of the block may be arbitrarily high, in this case Apple recommends to first fetch all of the objects, then to apply these filters.

unforgiven