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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With