iphone - 为什么 Xcode 4 将变量标记为未使用,即使它们是?

标签 iphone objective-c xcode4 nstimer compiler-warnings

我正在实例化和调度一个计时器变量,但 Xcode 编译器和分析器用 2 个警告标记我的变量“levelScoreTimer”,例如“警告:未使用的变量‘levelScoreTimer’和‘死存储:在初始化期间存储到‘levelScoreTimer’的值是从来没有读过”。我的声明有什么问题? scheduledTimerWithTimeInterval 方法实例化计时器并将其放在主运行循环中。我还在内部的选择器方法中停止计时器,因此肯定会使用计时器作为对象。有时类似案例我通过在第一行声明变量类型并在第二行进行赋值来将行分成两行。但这不是计时器对象的解决方案。有什么建议吗?这是我的声明和赋值:

NSTimer *levelScoreTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];

最佳答案

更改代码从

NSTimer *levelScoreTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(updateTotalScoreLabelFromTimeLeftLabel:) userInfo:nil repeats: YES];

关于iphone - 为什么 Xcode 4 将变量标记为未使用,即使它们是?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7009925/

相关文章:

iphone - 在iPhone App中获取Facebook用户名

ios - 为什么 UISearchBar 设置为第一响应者后仍然没有获得焦点?

ios - 每条堆栈跟踪行末尾的数字是什么意思?

objective-c - Swift 中 load 方法的替代方法

iphone - 已在项目中时找不到 xcode4 文件

xcode - OS X 10.7 : how to install XCode 4

iphone - 我是否应该询问网站是否需要使用他们的 rss feed 作为我的应用程序的数据?

iphone - 尝试使用 Reachable.h/.m 检查互联网访问时出错

iphone - 应用内购买 - 消耗品

iphone - 更改产品名称会导致问题吗?