Make the +/- Button For Assignment #1 Extra Credit

Below is my solution for one of the extra credit questions from assignment #1 from Stanford’s online CS193P class. Was trying to find a way to do it and found this post, it had an ok solution but the author mentions that a better solution would be something that manipulates the string instead of multiplying the display’s doubleValue. Here is what I came up with:

– (IBAction)plusMinusButtonPressed
    NSString *minusSymbol = @”-“;
    if ([self.display.text characterAtIndex:0] == ‘-‘) {
        NSRange myRange = NSMakeRange(0, [self.display.text length]);
        self.display.text = [self.display.text stringByReplacingOccurrencesOfString:@”-” withString:@”” options:NSLiteralSearch range:myRange];
    } else {
        self.display.text = [minusSymbol stringByAppendingString:self.display.text];