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

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];


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

Hope this works for you ;)

from stackoverflow
  • 本文作者: aisaka
  • 本文链接: 123.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 3.0 许可协议。转载请注明出处!