错误:“尝试使用appendString改变不可变对象:” --
我收到错误 “尝试使用appendString改变不可变对象:”
我的代码是
NSMutableString *resultString= [[NSMutableString alloc]init];
for (NSMutableString *s in self.ArrayValue)
{
[resultString appendString:s];
NSLog(resultString);
}
ArrayValue is NSMutableArray。
我无法理解问题出在哪里,
提前谢谢您
I am getting an error
'Attempt to mutate immutable object with appendString:'
and my code is
NSMutableString *resultString= [[NSMutableString alloc]init];
for (NSMutableString *s in self.ArrayValue)
{
[resultString appendString:s];
NSLog(resultString);
}
ArrayValue is NSMutableArray.
I am not able to understand where is the problem
thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如发布的那样,您拥有的代码不会给您所描述的错误。也许,在分配 resultString 和 for 循环之间的某个地方,您正在用普通的 NSSring 覆盖它。
As posted, the code you have will not give you the error you describe. Probably, somewhere between allocating resultString and the for loop, you are overwriting it with a normal NSSring.
就像这样:
它对我有用...
控制台上的O/P:
2011-03-08 19:13:02.243 iPadMables[4557:207] One
2011-03-08 19:13:06.224 iPadMables[4557: 207] OneTwo
2011-03-08 19:13:09.388 iPadMables[4557:207] OneTwoThree
Just do have like this:
It works for me...
O/P on Console:
2011-03-08 19:13:02.243 iPadMables[4557:207] One
2011-03-08 19:13:06.224 iPadMables[4557:207] OneTwo
2011-03-08 19:13:09.388 iPadMables[4557:207] OneTwoThree
为我工作..
works for me..