ios - How to get the Entity property from which an average is taken in CoreData -


i've fetched values coredata entity, averaged , groupedby date results. query works great. now... i've want know dates results come from. output shown raw result. how make query spit out date/groupby value (given groupby criteria date) averages taken from

the output

(         {         averageweight = 36;     },         {         averageweight = 22;     } ) 

the code:

nsfetchrequest *request = [[nsfetchrequest alloc] init];     nsentitydescription *entity = [nsentitydescription entityforname:@"exercisedata" inmanagedobjectcontext:context];     [request setentity:entity];      // specify request should return dictionaries.     [request setresulttype:nsdictionaryresulttype];      // create expression key path.     nsexpression *keypathexpression = [nsexpression expressionforkeypath:@"weight"];      // create expression represent function want apply     nsexpression *expression = [nsexpression expressionforfunction:@"average:"                                                          arguments:@[keypathexpression]];      // create expression description using minexpression , returning date.     nsexpressiondescription *expressiondescription = [[nsexpressiondescription alloc] init];      // name key used in dictionary return value.     [expressiondescription setname:@"averageweight"];     [expressiondescription setexpression:expression];     [expressiondescription setexpressionresulttype:nsinteger32attributetype]; // example, nsdateattributetype      // set request's properties fetch property represented expressions.     [request setpropertiestofetch:@[expressiondescription]];     request.predicate = [nspredicate predicatewithformat:@"exercise == %@",exercise];     [request setpropertiestogroupby:[nsarray arraywithobject:@"date"]];     // execute fetch.     nserror *error;     nsarray *objects = [context executefetchrequest:request error:&error];     nslog(@"%@",objects); 

just add "date" property fetch:

[request setpropertiestofetch:@[expressiondescription, @"date"]]; 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -