Reputation: 6940
i have an app that parse an XML i added to my application bundle, it con taint child nodes with string, sometimes it long enough, so i can't get it in output as full (i only get "last" part of string). This his how i tried to fix problem:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if (isDescription) [self._currentPosition setValue:string forKey:@"description"];
if (isDescription) {
if (self._currentPosition[@"description"])
{
NSMutableString *str = self._currentPosition[@"description"];
[str appendString:self.descriptionString];
}
else
{
[self._currentPosition setValue:[NSMutableString stringWithString:self.descriptionString] forKey:@"description"];
}
};
}
self.description string is a string i declared in .h file to make it mutable, but still, i got an error SIGABRT - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:'
Is there another way to fix that? I had same problem in other app, but previous code fix that just fine, but now i parse an XML i add to application bundle, and in another case that was just a web source.
So my question is - how to make "complete" string to fully output it?
There is a bit more information for you that might be useful - a console output of my string:
2014-02-16 16:01:51.500 superApp[294:60b] Ло́бное ме́сто — памятник древнерусской архитектуры, находящийся в Москве, на Красной площади. Представляет собой возвышение, окружённое каменной оградой.
2014-02-16 16:01:51.527 superApp[294:60b] лощади.
In text output in only get - "лощади."
Any advice would be appreciated, thanks!
Upvotes: 0
Views: 48
Reputation: 17043
Probably self._currentPosition[@"description"] is NSString, not NSMutableString. You should change this
NSMutableString *str = self._currentPosition[@"description"];
to this
NSMutableString *str = [[self._currentPosition[@"description"] mutableCopy];
Upvotes: 1
Reputation: 4660
This line
NSMutableString *str = self._currentPosition[@"description"];
Should be
NSMutableString *str = [NSMutableString stringWithString:self._currentPosition[@"description"]];
Upvotes: 1