how to mask an unwanted “Dead Store” warning in XC

2019-02-15 18:26发布

问题:

How to mask an unwanted "Dead Store" warning in XCode? That is I have this code for which I don't think it's an issue, so if this is the case I don't want to keep seeing the warning...(welcome for feedback however)

Code is here:

// Position and Size Labels in Cell
CGFloat currVertPos = 0; // Maintain lowest position, i.e. starting vertical point for next cell

// Set Position & Get back next veritical position to use
currVertPos = [self resizeLabel:_mainLabel atVertPos:currVertPos];
    currVertPos = [self resizeLabel:_mainLabel2 atVertPos:currVertPos];
    currVertPos = [self resizeLabel:_mainLabel3 atVertPos:currVertPos];
currVertPos = [self resizeLabel:self.secondLabel atVertPos:currVertPos];  // WARNING OCCURS HERE 

Warning Detail = Value stored "currVertPos" at is never read.

So it's true that for the last line the "currVertPos" isn't needed, but does it really matter, and if not how can I silence the warning?

回答1:

No, the warning doesn't matter; you can eliminate it simply by not doing the store. Delete the currVertPos = from the last line and there will be nothing to warn you about.



回答2:

One other alternative is to use:

#pragma unused(currVertPos)

Source: https://stackoverflow.com/questions/194666/is-there-a-way-to-suppress-warnings-in-xcode