I’m starting to develop for the iPhone. I have a beginner-type question, I’m sure:
I have this, which works:
testLabel.text = [NSString stringWithFormat:@"%@ to %@", testLabel.text, newLabelText];
I wish I could use the “+=” operator, but I get a compile error (Invalid operands to binary +, have ‘struct NSString *’ and ‘struct NSString *’):
testLabel.text += [NSString stringWithFormat:@"to %@", newLabelText];
Why can’t I do this?
Also, how can I shorten my first snippet of code?
You can’t use the
+=operator because C and Objective-C do not allow operator overloading. You’re trying to use+=with two pointer types, which is not allowed — if the left-hand side of a+=expression has a pointer type, then the right-hand side must be of an integral type, and the result is pointer arithmetic, which is not what you want in this case.