title: How to get the Entity property from which an average is taken in CoreData
body: <p>I've fetched some values from my <code>CoreData Entity</code>, <code>Averaged</code> and <code>GroupedBy</code> <code>date</code> the results. The query works great. Now... I've want to know the <code>dates</code> from which those results come from. The output shown is from the raw result. How could I make my query also spit out the <code>date</code>/<code>GroupBy value</code> <code>(given that my GroupBy criteria is date)</code> from which those averages where taken from</p>
  
  <p><strong>The output</strong></p>
  
  <pre><code>(
          {
          averageWeight = 36;
      },
          {
          averageWeight = 22;
      }
  )
  </code></pre>
  
  <p><strong>The Code:</strong></p>
  
  <pre><code>NSFetchRequest *request = [[NSFetchRequest alloc] init];
      NSEntityDescription *entity = [NSEntityDescription entityForName:@"ExerciseData" inManagedObjectContext:context];
      [request setEntity:entity];
  
      // Specify that the request should return dictionaries.
      [request setResultType:NSDictionaryResultType];
  
      // Create an expression for the key path.
      NSExpression *keyPathExpression = [NSExpression expressionForKeyPath:@"weight"];
  
      // Create an expression to represent the function you want to apply
      NSExpression *expression = [NSExpression expressionForFunction:@"average:"
                                                           arguments:@[keyPathExpression]];
  
      // Create an expression description using the minExpression and returning a date.
      NSExpressionDescription *expressionDescription = [[NSExpressionDescription alloc] init];
  
      // The name is the key that will be used in the dictionary for the return value.
      [expressionDescription setName:@"averageWeight"];
      [expressionDescription setExpression:expression];
      [expressionDescription setExpressionResultType:NSInteger32AttributeType]; // For example, NSDateAttributeType
  
      // Set the request's properties to fetch just the property represented by the expressions.
      [request setPropertiesToFetch:@[expressionDescription]];
      request.predicate = [NSPredicate predicateWithFormat:@"exercise == %@",exercise];
      [request setPropertiesToGroupBy:[NSArray arrayWithObject:@"date"]];
      // Execute the fetch.
      NSError *error;
      NSArray *objects = [context executeFetchRequest:request error:&amp;error];
      NSLog(@"%@",objects);
  </code></pre>