NSMutableString stringWithString:NSString not working for me
This piece of code below is causing my app to crash
EDIT
@interface termsAndConditions : NSObject开发者_高级运维
{
NSMutableString *titleText;
NSMutableString *bodyText;
NSMutableArray *arrayBodyText;
}
@property (nonatomic, copy) NSMutableString *titleText;
@property (nonatomic, copy) NSMutableString *bodyText;
*EDIT*
else if ([[self.arrayBodyText objectAtIndex:x] isKindOfClass:[NSString class]])
{
if (x == 0)
{
self.bodyText=[NSMutableString stringWithString:[self.arrayBodyText
objectAtIndex:x]];
}
else
{
[self.bodyText appendString:[self.arrayBodyText objectAtIndex:x] ];
}
the arrayBodyText is an array of NSString which I got from a dictionary and that I want to join them altogether in 1 NSMutableString.
When the app crashes it gives the message :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:' * Call stack at first throw:
Basically I need help to read this array of NSStrings into 1 NSMutableString.
Thanks -Code
Do this:
self.bodyText = [[[self.arrayBodyText componentsJoinedByString:@""] mutableCopy] autorelease];
精彩评论