George Asda
George Asda

Reputation: 2129

Incompatible pointer initializing NSMutableString with an expression of type NSString - Warning

Hi guys i got this piece of code and got a warning "Incompatible pointer initializing NSMutableString with an expression of type NSString" and a mem leak. does anyone seem to know how to correct this?

- (IBAction)numberClicked:(id)sender {

    UIButton * numberBtn = (UIButton*)sender;

    NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : self.textField.text );
    [value appendString:[NSString stringWithFormat:@"%d",numberBtn.tag]];

    self.textField.text = value;
}

thnaks

Upvotes: 2

Views: 3412

Answers (1)

Simon Whitaker
Simon Whitaker

Reputation: 20566

To get rid of the incompatible pointer warning, you need to assign a mutable copy of self.textField.text to value:

NSMutableString *value = (self.textField.text == nil ? [NSMutableString new] : [self.textField.text mutableCopy] );

Upvotes: 4

Related Questions