0

I have a list of const static doubles. I want to convert them to const static NSDecimalNumber*s. Is this possible? If not, what's a good alternative?

Ky -
  • 30,724
  • 51
  • 192
  • 308

1 Answers1

0

Unlike other Objective-C numbers (e.g. NSInteger), NSDecimalNumber is a runtime-evaluated object, and thus cannot be evaluated at compile time. Due to this, you must treat it as the object it is.

So, replace your:

const static double YourNumber = 123.456;

@implementation YourClass
// ...
@end

with:

NSDecimalNumber *YourNumber;

@implementation YourClass
+(void) initialize
{
    YourNumber = [NSDecimalNumber decimalNumberWithString:@"123.456"];
}

// ...
@end
Ky -
  • 30,724
  • 51
  • 192
  • 308