NSMutableString stringByReplacingOccurrencesOfString Warning
iphone, objective-c
Solution
If `currentSummary` is already a NSMutableString you shouldn't attempt to assign a regular NSString (the result of `stringByReplacingOccurrencesOfString:withString:`) to it.
Instead use the mutable equivalent `replaceOccurrencesOfString:withString:options:range:`, or add a call to `mutableCopy` before the assignment:
// Either
[currentSummary replaceOccurencesOfString:@"\n"
withString:@""
options:NULL
range:NSMakeRange(0, [receiver length])];
// Or
currentSummary = [[currentSummary stringByReplacingOccurrencesOfString:@"\n"
withString:@""]
mutableCopy];
Problem
I've got an RSS parser method and I need to remove whitespace and other nonsense from my extracted html summary. I've got a NSMutableString type 'currentSummary'. When I call: ``` currentSummary = [currentSummary stringByReplacingOccurrencesOfString:@"\n" withString:@""]; ``` Xcode tells me "warning: assignment from distinct Objective-C type" What's wrong with this?