Check some edge-cases Division by 0, double decimal points, leading 0s, …
Division by 0 is already handled in the code from the previous task.
For the double decimal points expand the commaPressed: method like in assignment #1:
- (IBAction)commaPressed:(UIButton *)sender { if (textFieldShouldBeCleared) { self.numberTextField.text = @"0."; textFieldShouldBeCleared = NO; } else if ([self.numberTextField.text rangeOfString:@"."].location == NSNotFound) { self.numberTextField.text = [self.numberTextField.text stringByAppendingString:@"."]; } }
And for the leading zeros set textFieldShouldBeCleared like before:
- (void)viewDidLoad { ... textFieldShouldBeCleared = YES; } - (IBAction)resultButtonPressed:(id)sender { ... textFieldShouldBeCleared = YES; } - (IBAction)numberEntered:(UIButton *)sender { if (textFieldShouldBeCleared) { ... if (sender.tag != 0) textFieldShouldBeCleared = NO; } ... } - (IBAction)clearDisplay:(id)sender { ... textFieldShouldBeCleared = YES; }
At this point there is still no MVC but at least the functionality from the previous assignment …
… however as we use floats the results might not what you would expect ;).