Using stringByAppendingString to add a character to an existing string in Xcode / objective-C

I am trying to add the character "1" to the existing value of the "output" of a text field in Xcode objective-C.

I am trying to use the function "stringByAppendingString" and have examined some examples and cannot make this work.

Is my syntax wrong?

- (IBAction)pressOne:(id)sender { NSString *str1 = output.text; output.text = [str1 stringByAppendingString:[@"1"]; } 
+4
source share
3 answers

Get rid of the wandering bracket before the @ symbol:

 output.text = [str1 stringByAppendingString:@"1"]; 
+4
source

try [str1 stringByAppendingString:@"1"];

+1
source

Remove the brackets:

 output.text = [str1  stringByAppendingString:@"1"]; 
0
source

Source: https://habr.com/ru/post/1402004/


All Articles