I have something like this on my core data class to fetch all data of kind “dataX” from the database, as an array…
+ (NSArray *)allDataInManagedObjectContext:(NSManagedObjectContext *)context
{
NSArray *allData = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"myData" inManagedObjectContext:context];
[request setResultType:NSDictionaryResultType];
[request setReturnsDistinctResults:YES];
[request setPropertiesToFetch:[NSArray arrayWithObject:@"dataX"]];
NSError *error = nil;
allData = [context executeFetchRequest:request error:&error];
[request release];
return allData;
}
The problem is that this returns an array of dictionaries and in this case, each dictionary contains just one pair object/key.
As all the keys on all dictionaries on that array are equal to “dataX”, I would like to receive, instead, an array containing just the values… so instead of this
array { dictionary1, dictionary2...
dictionary1 = one object for key "dataX" (lets call it object1)
dictionary2 = one object for key "dataX" (lets call it object2)
etc...
I would like to receive this
array {object1, object2, ...
is there a way to do that in the fetch itself?
thanks
use this.