Search code examples
iosobjective-cnsdecimalnumbernsuinteger

Pass a variable to decimalNumberHandlerWithRoundingMode?


Forgive me if I use the wrong terminology as I'm still a little new at iOS development. I've built a calculator-type app and I want users to be able to control how numbers are rounded. Here's the code I'm using:

-(NSString*)calculateWidthFromHeightString:(NSString*)height usingDimensions:(Favorite*)dimensions{

int decimalPlaces = [self.userData.rounding intValue];

NSUInteger *roundingMethod;
if ([self.userData.roundingMode isEqualToString:@"up"]) {
  roundingMethod = NSRoundUp;
}
else if ([self.userData.roundingMode isEqualToString:@"plain"]) {
    roundingMethod = NSRoundPlain;
}
else {
    roundingMethod = NSRoundDown;
}

NSDecimalNumberHandler *handler = [NSDecimalNumberHandler decimalNumberHandlerWithRoundingMode:roundingMethod
scale:decimalPlaces
raiseOnExactness:NO
raiseOnOverflow:NO
raiseOnUnderflow:NO
raiseOnDivideByZero:NO];

This works as expected, but I'm getting the following compiler warning where I assign the rounding mode to the pointer "roundingMethod":

Incompatible Integer to pointer conversion assigning to ‘NSUInteger *’ (aka ‘unassigned long *) from ‘NSUInteger’ (aka ‘unassigned long’) Incompatible Integer to pointer conversion assigning to ‘NSUInteger *’ (aka ‘unassigned int *) from ‘NSUInteger’ (aka ‘unassigned int’)

I don't really know what this means. Any help would be greatly appreciated.


Solution

  • This line:

    NSUInteger *roundingMethod;
    

    should be:

    NSUInteger roundingMethod;
    

    NSUInteger is a native type, not a class type.