Skip to content

Commit

Permalink
Fix return type of aggregate methods — it's not guaranteed to be an N…
Browse files Browse the repository at this point in the history
…SNumber

Closes magicalpanda#709
  • Loading branch information
tonyarnold authored and naqi committed Apr 7, 2016
1 parent 16ac7db commit 098a53d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
+ (BOOL) MR_hasAtLeastOneEntity;
+ (BOOL) MR_hasAtLeastOneEntityInContext:(NSManagedObjectContext *)context;

+ (NSNumber *) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context;
+ (NSNumber *) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate;
+ (id) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context;
+ (id) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate;

/**
* Supports aggregating values using a key-value collection operator that can be grouped by an attribute.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (id) MR_objectWithMinValueFor:(NSString *)property
return [self MR_objectWithMinValueFor:property inContext:[self managedObjectContext]];
}

+ (NSNumber *) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context
+ (id) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate inContext:(NSManagedObjectContext *)context
{
NSExpression *ex = [NSExpression expressionForFunction:function
arguments:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:attributeName]]];
Expand All @@ -125,12 +125,11 @@ + (NSNumber *) MR_aggregateOperation:(NSString *)function onAttribute:(NSString
[request setResultType:NSDictionaryResultType];

NSDictionary *resultsDictionary = [self MR_executeFetchRequestAndReturnFirstObject:request inContext:context];
NSNumber *resultValue = [resultsDictionary objectForKey:@"result"];

return resultValue;
return [resultsDictionary objectForKey:@"result"];
}

+ (NSNumber *) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate
+ (id) MR_aggregateOperation:(NSString *)function onAttribute:(NSString *)attributeName withPredicate:(NSPredicate *)predicate
{
return [self MR_aggregateOperation:function
onAttribute:attributeName
Expand Down

0 comments on commit 098a53d

Please sign in to comment.