LoginSignup
3
3

More than 5 years have passed since last update.

NSMutableStringを使った箇所でが何故かiOS7でだけコケる

Last updated at Posted at 2014-01-09

NSMutableStringをいじろうと思ったら以下のようなエラーが出ました。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with insertString:atIndex:'

今まで以下のように無理やりキャストしていたのがダメだったみたいです。

NSMutableString *str = (NSMutableString *)self.text.text;
[str insertString:@"hoge" atIndex:insertIndex];

キャストでなく、ちゃんとNSStringをNSMutableStringに変換してコピーしてくれるメソッドがありました。

NSMutableString *str = [self.text.text mutableCopy];

これだけでなおりました。
ios6以下では発生しなかったので、ios7から仕様が変わったのかもしれません。

3
3
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3