I created a category for NSDecimalNumber
in which I take an NSString
and return a NSDecimalNumber
. I'm using it in a few of my view controllers and wanted to create a single global instance of NSNumberFormatter
. I think this works but I have no idea on how to test it. For example, I want to NSLog every time an NSNumberFormatter
instance gets allocated. How do I do that?
#import "NSDecimalNumber+amountFromTextField.h"
@implementation NSDecimalNumber (amountFromTextField)
static NSNumberFormatter *nf;
+(NSDecimalNumber *)amountFromTextField:(NSString *)amount {
@synchronized(self) {
if (nf == nil) {
nf = [[NSNumberFormatter alloc] init];
}
}
NSDecimal _amount = [[nf numberFromString:amount] decimalValue];
return [NSDecimalNumber decimalNumberWithDecimal:_amount];
}
@end