Hey guys I’m trying to make a basic calculator (polish style) but can’t figure out why my code to stop double decimal entry won’t work. I found a different way on another thread, but I want to understand why my code won’t work. I’m using an nsRange to search the already entered digits in the label for a decimal, then a second conditional to see if the digit to be appended is a decimal Please help..
- (IBAction)digitPressed:(UIButton *)sender
{
NSString *digit = [sender currentTitle]; // the number on the button pressed
NSString *decimalErrorChecker = [[self display] text]; //search line for .
NSRange range = [decimalErrorChecker rangeOfString:@"."];
if ((range.location != NSNotFound) && ((digit == @"."))) { //double if to stop 2nd
//SHOW ERROR
}else //APPEND DIGIT TO ALREADY ENTERED String.
Compare NSString using
isEqualToString, not==: