《死亡商店》 Xcode 中的警告

发布于 2024-12-07 08:34:20 字数 576 浏览 1 评论 0原文

当我分析我的项目时,我收到死店警告,但项目没有崩溃。 这就是我正在做的事情,

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 技术交流群。

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

发布评论

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

评论(3

梦境 2024-12-14 08:34:20

该警告告诉您,您在第一行中执行的存储被丢弃(即为变量分配一个空字符串,然后在不使用原始值的情况下重新分配它)。只需将第一行更改为以下内容,警告就会消失:

NSString *aUrl;

编辑:

您还应该更改使用它的行:

aURL = [aValue copy];

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:

NSString *aUrl;

Edit:

you should change the line where you use it also:

aURL = [aValue copy];
分开我的手 2024-12-14 08:34:20

“死店”意味着没有使用过的东西,或者更确切地说是无用的东西。

当您定义了一个从未对其执行任何操作的变量时,您就会得到它。因此,分析器会告诉您,您浪费了一些存储空间。

这里你在分配 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.

心在旅行 2024-12-14 08:34:20

死存储是指已分配但从未使用过的值。没有什么可担心的。但如果你无法控制自己不担心;-)你可以将你的代码更改为,

NSString aUrl = nil;

if ([anArray count] == 1) {

    // a value is store in aValue
    // then that value is appended to aURL
    aURL = [aURL stringByAppendingString:aValue];

} else {

    aUrl = @"";
    //someother operation is done and a value is loaded to aURL
}

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,

NSString aUrl = nil;

if ([anArray count] == 1) {

    // a value is store in aValue
    // then that value is appended to aURL
    aURL = [aURL stringByAppendingString:aValue];

} else {

    aUrl = @"";
    //someother operation is done and a value is loaded to aURL
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文