Xcode中的"死店"警告

lea*_*010 0 xcode memory-management nsstring ios

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

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
}
Run Code Online (Sandbox Code Playgroud)

我在代码中提到了一个死店警告.我怎么能阻止这个?

如果有人能帮我解决这个问题会很棒

小智 6

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

NSString *aUrl;
Run Code Online (Sandbox Code Playgroud)

编辑:

你应该改变你使用它的行:

aURL = [aValue copy];
Run Code Online (Sandbox Code Playgroud)