在从一家外包开发公司继承了一个项目后,我被要求修改应用程序并添加一些功能。
作为一个完美主义者(但仍然是相对较新的),我试图在编译时消除项目中的警告。
我得到了这个错误
函数末尾未使用的变量'timer‘
其在超时之后将刷新按钮设置回启用。
我如何重写这段代码,这样我就不会得到未使用的(我不能注释掉它,因为它实际上正在做它应该做的事情,即在计时器过期后重新设置状态)。
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
//lots of previous code
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];
}发布于 2011-08-12 16:31:20
只需删除赋值并将其读取:
[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];没有NSTimer *timer =的话。
显然,不需要指向timer对象的指针,因为它只是做它应该立即做的事情。还是我错过了什么?
发布于 2011-08-12 19:38:41
如果您稍后仍需要在该方法中引用该计时器,请执行以下操作:
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
//lots of previous code
NSTimer *timer;
timer=[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(enableRefresh) userInfo:nil repeats:NO];
//lots of other code
}发布于 2011-08-12 19:45:14
总是有假操作:
(void)timer;我经常使用它来避免未使用的参数警告,甚至使其成为宏。
https://stackoverflow.com/questions/7037358
复制相似问题