【发布时间】:2014-06-01 17:27:08
【问题描述】:
当我使用appendString: 将字符串附加到NSMutableString 时,出现以下错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Attempt to mutate immutable object with appendString:'
我的代码是:
self.partialWord = [NSMutableString stringWithCapacity:self.wordLength];
for (int i=0; i<wordLength; i++) {
[self.partialWord appendString:@"-"];
}
在我的头文件中:
@property (copy, nonatomic, readwrite) NSMutableString *partialWord;
我不明白为什么它说对象是不可变的,因为它是NSMutableString。为什么[self.partialWord appendString:@"-"]; 部分不起作用?
【问题讨论】:
标签: ios objective-c nsmutablestring declared-property