简体   繁体   English

XCode警告“表达式结果未使用”的数学陈述

[英]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.) +2是有效的表达式,除了产生值2外,不执行任何操作,因此发出警告。)

So, remove the semicolon from your define, or, even better, stop using #define when a static const int would do. 因此,从您的定义中删除分号,或者甚至更好的是,当静态const int可以使用时,停止使用#define (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 该警告告诉您创建了一个名为viewHeight的CGFloat,并且未在代码中使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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