OC-2 invalid operands to binary expression ('NSString *' and 'NSString *')q

  2016-7-31 


Q: I have the following code:

NSString  *String=TextField1.text + TextField2.text 

its giving the error: -invalid operands to binary expression ('NSString *' and 'NSString *') An:

You cannot do it this way, because objective-c doesn’t use ‘+’ operator for concatenation This way should work:

NSString *concat = [NSString stringWithFormat@"%@%@", TextField1.text, TextField2.text];

or

NSString *concat = [TextField1.text stringByAppendingString:TextField2.text];

Hope this works for you ;)

from stackoverflow

且听风吟