简体   繁体   中英

XCode Warning “Expression Result Unused” for mathematical statement

I am getting a warning while doing this

CGFloat viewHeight = ([self.quotaArray count]*kROW_HEIGHT) + kHEADER_HEIGHT + kFOOTER_HEIGHT;

Basically this math statement returns me the height of my table view, which is the

(number of rows * row height) + header height + footer height

What am I doing wrong?

My guess: You have something like:

#define kHEADER_HEIGHT 3;

So, the line of code you give turns into:

CGFloat viewHeight = ([self.quotaArray count]*1) + 3; + 2;

Which is valid; the last part produces a warning. ( +2 is a valid expression, which does nothing but produce the value 2, hence the warning.)

So, remove the semicolon from your define, or, even better, stop using #define when a static const int would do. (Because you can't get crazy errors like this if you're just using an int.)

Are you using the variable after it? That warning is telling you that you created a CGFloat called viewHeight and not using it in your code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM