If I set a mutable string’s value to a value from an array, and use the following code to manipulate it:
NSMutableString *theCountry = [listItems objectAtIndex:3];
theCountry = [theCountry stringByReplacingOccurrencesOfString:@"\"" withString:@""];
I receive the warning “warning: assignment from distinct Objective-C type” after the second line of the above code. If I do not have “theCountry =” before the method call, the warning goes away, but the string does not get manipulated…
The
stringByReplacingOccurrencesOfString:withString:method is declared to return anNSString*, not anNSMutableString*. Basically, in the assignment, you’re assigning anNSString*to a variable of typeNSMutableString*which is not necessarily safe (note thatNSMutableStringinheritsNSString, not the other way around).