Objective-C:NSMutableString 错误
我不断收到此代码的错误,应用程序告诉我我正在尝试改变一个不可变的对象。有人可以看一下并解释我做错了什么吗?谢谢。
thisrow = [NSString stringWithFormat:@"%i", startPointX2];
NSMutableString* setCoordStr = [[NSMutableString alloc] init];
[setCoordStr appendFormat: thisrow];
if(w==1) {
thiscol = [NSString stringWithFormat:@"%i", endPointY];
[setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
} else {
for(startPointY; startPointY<endPointY+1; startPointY++) {
thiscol = [NSString stringWithFormat:@"%i", startPointY];
[setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
}
}
NSLog(@"%@ ", setCoordStr);
I keep getting an error with this code, the app is telling me I am trying to mutate an object which is not mutable. Can someone take a look and explain what I am doing wrong? Thanks.
thisrow = [NSString stringWithFormat:@"%i", startPointX2];
NSMutableString* setCoordStr = [[NSMutableString alloc] init];
[setCoordStr appendFormat: thisrow];
if(w==1) {
thiscol = [NSString stringWithFormat:@"%i", endPointY];
[setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
} else {
for(startPointY; startPointY<endPointY+1; startPointY++) {
thiscol = [NSString stringWithFormat:@"%i", startPointY];
[setCoordStr insertString:thiscol atIndex:[setCoordStr length]];
}
}
NSLog(@"%@ ", setCoordStr);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
appendString:
而不是第一个appendFormat:
和insertString:atIndex:
You could used
appendString:
instead of your firstappendFormat:
and yourinsertString:atIndex: