views:

251

answers:

2

Hello,

Unless I have missed something in the documentation, I can't see if it is possible to execute an NSFetchRequest so that it returns an array of properties of objects, instead of the objects themselves.

For example, I have:
@interface SaleDate {
NSDate *open;
NSDate *close;
Sale *sale;
}

I want to query something like "close >= $today". However, this gives me an array of SaleDate, when what I really want is a distinct array of Sale. I am using this with a NSFetchedResultsController and so need it to deal with Sale object.

Incidentally, I have another (preferred) query working when using a binary store - it's the SQLite store that is making me go though hoops to find an alternate but equivalent query.

Thanks

+1  A: 

iPhone OS 2.x and Mac OS X 10.5 do not have this functionality.

See the NSFetchRequest documentation for iPhone OS 3.0, which does.

In particular, you want to look at

-setResultType:
-setReturnsDistinctResults:
-setPropertiesToFetch:
Jim Correia
A: 

If you have an array of SaleDate and want an array of Sale, just write:

NSArray *arrayOfSale = [arrayOfSaleDate valueForKeyPath:"@sale"];

This assumes that SaleDate is KVC-compliant for the "sale" member. If SaleDate is a managed object and "sale" is a modeled property, this is already the case.

Frank Szczerba