【发布时间】:2015-08-19 20:02:08
【问题描述】:
您好,我正在尝试在 Swift 2.0 项目的一个类中使用 NSTimer。我想使用let 常量作为时间间隔,但它总是显示错误“字符串不可转换为 stringLiteralConvertible”。当我使用一个简单的数字时它可以工作,但我需要一个常量
func setupLocationUpdateInterval(seconds: Int)
{
timer?.invalidate()
timer = NSTimer.scheduledTimerWithTimeInterval(seconds, target: self, selector: "startUpdatingLocation", userInfo: nil, repeats: true)
}
【问题讨论】:
-
在您尝试使用 let 常量的地方显示您的代码,以便我们看到您尝试了什么。
-
需要提一下的是swift 2.0
-
秒是常数,它显示与我使用 let seconds = 10... 相同的错误...
-
scheduledTimerWithTimeInterval的第一个参数的类型必须是NSTimeInterval(双)而不是Int -
@vadian 正如我在下面的回答中所说的那样。
标签: ios swift constants nstimer swift2