Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning NSMutableString from NSString Warning

I have the following three lines of code in my program:

NSMutableString *stringOne = [NSMutableString stringWithFormat:@"Hello "];
NSMutableString *stringTwo = [NSMutableString stringWithFormat:@"World"];
NSMutableString *sayIt = [stringOne stringByAppendingString:stringTwo];

Despite the fact that it works, the third line is causing the warning Assigning NSMutableString * from NSString *.

I am at a loss here since everything I am using is an NSMutableString.

like image 809
Scooter Avatar asked Dec 28 '25 17:12

Scooter


1 Answers

Not quite. stringByAppendingString does not return an NSMutableString. Instead do the following:

NSMutableString *sayIt = [NSMutableString stringWithString:stringOne];
[sayIt appendString:stringTwo];

Or

NSMutableString *sayIt = [[stringOne stringByAppendingString:stringTwo] mutableCopy];
like image 81
XJones Avatar answered Dec 31 '25 11:12

XJones



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!