2

Im inserting a string into a NSMutableString like as

NSMutableString *string = (NSMutableString *)self.label.text;
[string insertString:@"New " atIndex:0];

these line of codes working properly iOS 6 device. but in iOS 7 it throws an exception as Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds' (i'm running ios 6 app in ios 7 device).

can any body tell why it's happening? please.

thanks

Srinivas
  • 315
  • 3
  • 18

1 Answers1

1

You can't convert an NSString to an NSMutableString simply by casting. Do this instead:

NSMutableString *string = [self.label.text mutableCopy];
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • thanks, it's working. But one doubt, how it is working in ios 6 and not in ios 7?. Could you please tell me why? – Srinivas Oct 10 '13 at 05:03
  • 3
    Honestly, I have no idea how your code ever worked. It should have caused problems since iOS 2.0. – rmaddy Oct 10 '13 at 05:05