NSString stringByAppendingString:递归长字符串
一段时间以来,我在使用 NSStrings 并将其附加到另一个字符串时遇到了系统问题。我在网上搜索,但找不到令我满意的东西。
我在标头中声明了一个这样的字符串,并在实现中正确合成:
@property (nonatomic, retain) NSString *dataString;
我每 200 毫秒刷新一次数据。我想在旧的递归之后将其放入一个字符串中(我猜 NSData 会更好)。那么字符串应该每 200 毫秒增长一次。
dataString = [dataString stringByAppendingString:superString];
NSLog(@"%@",dataString);
但我的代码在这里被破坏了!
日志数据:
2011-07-05 12:40:54.039 Acceleration[1658:307] /AccelerationApp2011-07-05_12:40.txt
2011-07-05 12:40:56.825 Acceleration[1658:307] Acceleration:
X-axis: -0.036224
Y-axis: -0.036224
Z-axis: -0.941833
Global Acc: 0.9 g
(gdb)
...然后我收到程序收到的信号:EXC_BAD_ACCESS
问题是字符串可能太长吗?
i have now since a while a systematic problem with NSStrings and appending these to another. I searched in the web, but i couldn't find something witch satisfied me.
I have a string declared like this in the header and properly syntesized in the implementation:
@property (nonatomic, retain) NSString *dataString;
I am refreshing every 200 ms data. I want to put this into a string (NSData would be more nice i guess) after the old one recursive. The string should grow every 200ms then.
dataString = [dataString stringByAppendingString:superString];
NSLog(@"%@",dataString);
But my code is is breaking here!
LOG DATA:
2011-07-05 12:40:54.039 Acceleration[1658:307] /AccelerationApp2011-07-05_12:40.txt
2011-07-05 12:40:56.825 Acceleration[1658:307] Acceleration:
X-axis: -0.036224
Y-axis: -0.036224
Z-axis: -0.941833
Global Acc: 0.9 g
(gdb)
...then i get program received signal: EXC_BAD_ACCESS
Is the Problem that the string may be too long?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要保留 stringByAppending... 的返回值或将其分配给您的属性:
You need to retain the return value from stringByAppending... or assign it to your property:
你没有保留它。
[dataString stringByAppendingString:superString];
返回一个自动释放的字符串。you're not retaining it.
[dataString stringByAppendingString:superString];
returns an autoreleased string.