Swift:'Int32' 不能转换为 'Int32'

Swift: 'Int32' is not convertible to 'Int32'

我正在使用 Swift 1.1xCode 6.1.1

进行项目

我在尝试从值和时间刻度中提取秒数时收到以下错误

PATH/ViewControllers/Camera/CaptureScreenViewController.swift:41:58: 'Int32' is not convertible to 'Int32'

在下一行

var seconds = CMTimeMakeWithSeconds(Float64(value),timescale)

,timescale)

下面几行供参考

var currentCellSegment = segmentForIndexPath(indexPath) var value = currentCellSegment.duration.value.value var timescale = currentCellSegment.duration.timescale.value var seconds = CMTimeMakeWithSeconds(Float64(value),timescale)

关于如何修复有什么建议吗?或者回答为什么会这样?

我尝试过的东西

我已经卸载了 xCode,重新启动并重新安装。

我已经尝试过像这样投射 timescale as Int32

var timescale = currentCellSegment.duration.timescale.value as Int32

var timescale: Int32 = currentCellSegment.duration.timescale.value

var timescale: Int32 = currentCellSegment.duration.timescale.value as Int32

,但我在 var timescale...

行收到错误

根据@martin-r

的建议

新参考码

var currentCellSegment = segmentForIndexPath(indexPath) var value = currentCellSegment.duration.value var timescale = currentCellSegment.duration.timescale var seconds = CMTimeMakeWithSeconds(Float64(value),timescale)

已解决

报错信息确实有点奇怪,不过解决方法是 可能是为了删除不必要的 .value 调用:

var value = currentCellSegment.duration.value
var timescale = currentCellSegment.duration.timescale

如果 currentCellSegment.durationstruct CMTime 那么它 timescale 属性 是 CMTimeScale 又名 Int32,也就是 CMTimeMakeWithSeconds() 期待什么。


value 属性 of Int32 returns a Builtin.Int32, 那 导致奇怪的错误信息。示例:

func abc(x : Int32) {
    println(x)
}
let x = Int32(1)
abc(x)       // OK
abc(x.value) // error: 'Int32' is not convertible to 'Int32'