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

时间:2015-03-31 19:54:53

标签: ios swift ios8.1 xcode6.1.1

我正在使用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,重新启动并重新安装。

我已经尝试过像这样<{1}} 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

收到错误 @ martin-r

建议

新参考代码

var timescale...

解决

1 个答案:

答案 0 :(得分:0)

错误消息确实有点奇怪,但解决方案是 可能要删除不必要的.value来电:

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

如果currentCellSegment.durationstruct CMTime,那么它就是timescale CMTimeScale属性是Int32又名CMTimeMakeWithSeconds(),就是这样 value期望的是什么。


Int32的{​​{1}}属性返回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'