我得到這個錯誤:如何解決這個突變錯誤?
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with replaceCharactersInRange:withString:'
但我想不出什麼不可變對象我變異。
NSRange subRange = [self.label.text rangeOfString: @"="];
int numA = 5;
int numB = 3;
NSMutableString *mixed = [NSString stringWithFormat: @"%i %i", numA, numB];
NSMutableString *string = [NSString stringWithString: self.label.text];
subRange = [string rangeOfString: @"="];
if (subRange.location != NSNotFound)
[string replaceCharactersInRange:subRange withString:mixed];
您的字符串變量不可變,並且您嘗試對其進行變異。 – Jeremy 2013-03-18 01:19:07
http://stackoverflow.com/questions/14541212/attempt-to-mutate-immutable-object-error http://stackoverflow.com/questions/8267956/error-for-attempting-mutating-immutable-object – Sebastian 2013-03-18 01:24:09