ios - Xcode 中的 "Dead Store"警告

标签 ios xcode memory-management nsstring

当我分析我的项目但项目没有崩溃时,我收到了死存储警告。 这是我正在做的

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
}

我收到了代码中提到的死存储警告。我该如何防止这种情况发生?

如果有人能帮我解决这个问题就太好了

最佳答案

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

NSString *aUrl;

编辑:

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

aURL = [aValue copy];

关于ios - Xcode 中的 "Dead Store"警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7597679/

相关文章:

ios - IOS5 上日期组件的星期数错误

iphone - Leaks Instrument 中的颜色和百分比表示什么?

ios - Xcode 不允许我添加 Outlets

ios - Xcode 6.3.2 无法与成员(member)中心通信

c++ - 使用分配器 Hook 时如何检索被释放的字节?

ios - JSON 解析使用 [NSJSONSerialization JSONObjectWithData :dataJson options:0 error:&error] thowing nil

objective-c - Xcode 6.4 Swift 单元测试无法编译 : "GPUImage.h not found" "failed to import bridging header"

delphi - 用于 Delphi XE2 的 SafeMM

iphone - Objective-C 在函数中返回分配的内存 == 不好?

ios - NSValidationMissingMandatoryPropertyError 问题,但所有字段都已填充