Using other answers in this forum I made this class method to tell if a string is a number. It works OK but do I have to alloc-init every time it is called? After all if this was not XCode4 that would constitute a memory leak wouldn't it? NB, I am using XCode4 which has the Automatic Reference Counter which will prevent that happening.
I was hoping to do something like
if this is not alloc-initted then alloc-init
but can't seem to get it to work.
Method as it stands currently
+ (BOOL)isThisANumber:(NSString *)candidate{
NSNumberFormatter *fmtr = [[NSNumberFormatter alloc] init];
[fmtr setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *myNumber = [fmtr numberFromString:candidate];
if ( myNumber== nil) {
return NO;
}
else{
return YES;
}