user440096
user440096

Reputation:

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

Upvotes: 0

Views: 410

Answers (1)

Jeremy W. Sherman
Jeremy W. Sherman

Reputation: 36143

Do this:

self.bodyText = [[[self.arrayBodyText componentsJoinedByString:@""] mutableCopy] autorelease];

Upvotes: 1

Related Questions