I have a method with a return value that I want to call from my MainviewController.m. Also, I must pass a value (float) to the method when calling it.
But I’m having trouble with that, I tried to debug and add some breakpoints and NSLog in the method but it appears that the method is not being called, since the debugger doesn’t stop at the breakpoint and doesn’t print the NSLog. (the final print (calculatorScreen.text…) just print (null))
MainViewController.m
currentNumber = currentNumber *10 + (float)[sender tag];
NSNumber *convertedNumber = [[NSNumber alloc] init];
NSString *nf = [convertedNumber customFormatNumber:currentNumber];
calculatorScreen.text = [NSString stringWithFormat:@"%@",nf]; // it's printing (null) :(
NSNumber+FormatNumber.h
@interface NSNumber (FormatNumber)
-(NSString *) customFormatNumber:(float)n1;
NSNumber+FormatNumber.m
-(NSString *) customFormatNumber:(float)n1
{
NSLog(@" %f" ,n1); // for debug and a breakpoint here
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:0];
NSString *nf = [formatter stringFromNumber:[NSNumber numberWithFloat:n1]];
NSLog(@"Class %@" ,nf); // for debug
return nf;
}
What am I missing here?
Are you trying to overwrite NSNumber?
For CustomNumber.h
For CustomNumber.m
Then in MainViewController.m
OR
In MainViewController.m create the method and then the code will be