NSString stringByAppendingString:递归长字符串

发布于 2024-11-18 21:26:39 字数 736 浏览 3 评论 0原文

一段时间以来,我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

っ左 2024-11-25 21:26:39

您需要保留 stringByAppending... 的返回值或将其分配给您的属性:

self.dataString = [self.dataString stringByAppendingString:superString];

You need to retain the return value from stringByAppending... or assign it to your property:

self.dataString = [self.dataString stringByAppendingString:superString];
叹梦 2024-11-25 21:26:39

你没有保留它。 [dataString stringByAppendingString:superString]; 返回一个自动释放的字符串。

[dataString autorelease];
dataString = [[dataString stringByAppendingString:superString] retain];

you're not retaining it. [dataString stringByAppendingString:superString]; returns an autoreleased string.

[dataString autorelease];
dataString = [[dataString stringByAppendingString:superString] retain];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文