Repository: realm/realm-swift
File: Realm/RLMArray.mm (Objective-C++)

Code before:
    else if (colType == RLMTypeDate) {
        @throw [NSException exceptionWithName:@"realm:operation_not_supported"
                                       reason:@"Minimum not supported on date columns yet"
                                     userInfo:nil];
    }
    else {
        @throw [NSException exceptionWithName:@"realm:operation_not_supprted"
                                       reason:@"Sum only supported on int, float and double columns."
                                     userInfo:nil];
    }
    
    return min;
}

-(id)maxOfProperty:(NSString *)property {
    NSUInteger colIndex = RLMValidatedColumnIndex([RLMObjectDescriptor descriptorForObjectClass:_objectClass], property);
    
    tightdb::TableView table = self.backingQuery->find_all();
    RLMType colType = RLMType(table.get_column_type(colIndex));
    
    id max;
    if (colType == RLMTypeInt) {
        max = [NSNumber numberWithInteger:table.maximum_int(colIndex)];
    }
    else if (colType == RLMTypeDouble) {
        max = [NSNumber numberWithDouble:table.maximum_double(colIndex)];
    }
    else if (colType == RLMTypeFloat) {
        max = [NSNumber numberWithDouble:table.maximum_float(colIndex)];
    }
    else if (colType == RLMTypeDate) {
        @throw [NSException exceptionWithName:@"realm:operation_not_supported"
                                       reason:@"Maximum not supported on date columns yet"
                                     userInfo:nil];
    }
    else {
        @throw [NSException exceptionWithName:@"realm:operation_not_supprted"
                                       reason:@"Maximum only supported on int, float and double columns."
                                     userInfo:nil];
    }
    
    return max;
}

-(NSNumber *)sumOfProperty:(NSString *)property {
    NSUInteger colIndex = RLMValidatedColumnIndex([RLMObjectDescriptor descriptorForObjectClass:_objectClass], property);
    
    tightdb::TableView table = self.backingQuery->find_all();
    RLMType colType = RLMType(table.get_column_type(colIndex));
    
    NSNumber *sum;

Review comment (suggestion):
Instead of populating id min and returning later, you could just return immediately in each if block. Then you wont need the else.

Also, you can create an NSNumber simply by wrapping a number in @(var). For example

```
[NSNumber numberWithInteger:table.minimum_int(colIndex)]
```

is equivalent to

```
@(table.minimum_int(colIndex))
```

Same feedback goes for other aggregate methods


Code after:
    RLMObjectDescriptor *desc = [RLMObjectDescriptor descriptorForObjectClass:_objectClass];
    RLMArray *array = [self copy];
    RLMUpdateQueryWithPredicate(array.backingQuery, predicate, desc);;
    array.backingView = array.backingQuery->find_all();
    return array;
}

- (RLMArray *)objectsOrderedBy:(id)order where:(id)predicate, ... {
    // validate predicate
    NSPredicate *outPred;
    RLM_PREDICATE(predicate, outPred);
    
    // copy array and apply new predicate
    RLMObjectDescriptor *desc = [RLMObjectDescriptor descriptorForObjectClass:_objectClass];
    RLMArray *array = [self copy];
    RLMUpdateQueryWithPredicate(array.backingQuery, predicate, desc);
    tightdb::TableView view = array.backingQuery->find_all();
    
    // apply order
    RLMUpdateViewWithOrder(view, order, desc);
    array.backingView = view;
    return array;
}

-(id)minOfProperty:(NSString *)property {
    NSUInteger colIndex = RLMValidatedColumnIndex([RLMObjectDescriptor descriptorForObjectClass:_objectClass], property);
    
    RLMPropertyType colType = RLMPropertyType(self.backingView.get_column_type(colIndex));
    
    switch (colType) {
        case RLMPropertyTypeInt:
            return @(self.backingView.minimum_int(colIndex));
        case RLMPropertyTypeDouble:
            return @(self.backingView.minimum_double(colIndex));
        case RLMPropertyTypeFloat:
            return @(self.backingView.minimum_float(colIndex));
        case RLMPropertyTypeDate:
            @throw [NSException exceptionWithName:@"realm:operation_not_supported"
                                           reason:@"Minimum not supported on date columns yet"
                                         userInfo:nil];
        default:
            @throw [NSException exceptionWithName:@"realm:operation_not_supprted"
                                           reason:@"Sum only supported on int, float and double columns."
                                         userInfo:nil];
    }
}

-(id)maxOfProperty:(NSString *)property {
    NSUInteger colIndex = RLMValidatedColumnIndex([RLMObjectDescriptor descriptorForObjectClass:_objectClass], property);
    
    RLMPropertyType colType = RLMPropertyType(self.backingView.get_column_type(colIndex));