无法将类型'String'的值分配为'NSTimeInterval'(又名'Double')

时间:2015-11-02 14:33:59

标签: swift audio time

我正在尝试将我的滑块值设置为声音currentValue,但后来我收到此错误:

Cannot assign value of type 'String' to type 'NSTimeInterval' (aka 'Double')

我是Xcode和错误的新手,所以我真的不知道如何解决这个问题,但我试图删除字符串部分但是没有用。

@IBAction func time(sender: UISlider) {

var timeValue:String = String(Int(sender.value)) sound!.currentTime = timeValue

}

1 个答案:

答案 0 :(得分:2)

timeValue是一个String,currentTime很可能是NSTimeInterval。您不能将字符串分配给NSTimeInterval。请改用Double(sender.value)。另外,我建议你不要在一行上组合这么多操作,特别是如果你不熟悉编程或Swift。如果您收到错误,如果您的sound变量为零或者其他内容正在发生,则您无法轻易查看问题是转换为字符串,还是转换为Int。

相关问题