《死亡商店》 Xcode 中的警告
当我分析我的项目时,我收到死店警告,但项目没有崩溃。 这就是我正在做的事情,
NSString *graphUrl = nil;
if ([graphArray count] == 1)
{
objTrial = [graphArray objectAtIndex:0];
graphUrl = @"http://chart.apis.google.com/chart?cht=s:nda&chf=bg,s,FFFFFF&chs=";
graphUrl = [graphUrl stringByAppendingString:@"&chd=t:"];
graphUrl = [graphUrl stringByAppendingString:objTrial.highValue];// get the dead store error here
}
else
{
//someother operation is done and a value is loaded to aURL
}
我收到代码中提到的死亡存储警告。我该如何防止这种情况?
如果有人能在这方面帮助我,那就太好了
I am getting a dead store warning when I analyze my project but the project does not crash.
Here is what I am doing
NSString *graphUrl = nil;
if ([graphArray count] == 1)
{
objTrial = [graphArray objectAtIndex:0];
graphUrl = @"http://chart.apis.google.com/chart?cht=s:nda&chf=bg,s,FFFFFF&chs=";
graphUrl = [graphUrl stringByAppendingString:@"&chd=t:"];
graphUrl = [graphUrl stringByAppendingString:objTrial.highValue];// get the dead store error here
}
else
{
//someother operation is done and a value is loaded to aURL
}
I get a dead store warning as mentioned in the code.. How can I prevent this?
It would be great if someone could help me out in this
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该警告告诉您,您在第一行中执行的存储被丢弃(即为变量分配一个空字符串,然后在不使用原始值的情况下重新分配它)。只需将第一行更改为以下内容,警告就会消失:
编辑:
您还应该更改使用它的行:
The warning is telling you that the store that you do in the first line gets thrown away (i.e assigning an empty string to the variable and then reassigning it afterwards without using the original value). Just change the first line to the following and the warning should go away:
Edit:
you should change the line where you use it also:
“死店”意味着没有使用过的东西,或者更确切地说是无用的东西。
当您定义了一个从未对其执行任何操作的变量时,您就会得到它。因此,分析器会告诉您,您浪费了一些存储空间。
这里你在分配 aUrl 对象后还没有使用它。
除了浪费一些字节的内存之外,它不会造成任何问题。当然,如果是大物体的话可能会更多。
也许有人可以利用编译器的知识来参与,因为编译器优化在任何情况下都可能会处理死存储。
"dead store" means something that's not used, or rather something useless.
You get it when you have a variable defined that you never do anything with. So, the Analyzer tells you that you have wasted some storage.
Here you haven't used the aUrl object after assigning it.
It won't cause any problems other than a few bytes of wasted memory. Of course if it's a large object that could be more.
Perhaps someone could chip in with knowledge of compilers, as compiler optimization might take care of dead stores in any case.
死存储是指已分配但从未使用过的值。没有什么可担心的。但如果你无法控制自己不担心;-)你可以将你的代码更改为,
Dead Store is a value that is assigned but never used. There is nothing to worry about it. But if you can't control yourself from worrying ;-) you can change your code to,