AdamL
AdamL

Reputation: 177

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

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

I am trying to use the "stringByAppendingString" function, and have looked at some examples and can't seem to get this to work.

Is my syntax just wrong?

- (IBAction)pressOne:(id)sender {
    NSString *str1 = output.text;

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

}

Upvotes: 4

Views: 8403

Answers (3)

jlehr
jlehr

Reputation: 15597

Get rid of the stray bracket before the @ symbol:

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

Upvotes: 4

sooper
sooper

Reputation: 6039

try [str1 stringByAppendingString:@"1"];

Upvotes: 1

sch
sch

Reputation: 27506

Remove the brackets:

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

Upvotes: 0

Related Questions