【问题标题】:Swift: 'Int32' is not convertible to 'Int32'斯威夫特:“Int32”不能转换为“Int32”
【发布时间】:2015-03-31 19:54:53
【问题描述】:

我正在使用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)

已解决

【问题讨论】:

    标签: ios swift ios8.1 xcode6.1.1


    【解决方案1】:

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

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

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


    Int32value 属性返回 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'
    

    【讨论】:

    • 我收到错误 - PATH/ViewControllers/Camera/CaptureScreenViewController.swift:41:21: 无法使用类型为 '($T2, @lvalue CMTimeScale)' 的参数列表调用line var seconds...更新帖子
    • @MarkMasterson:您没有正确复制第一行,只有 last .value 必须被删除。
    • 是的!注意到查看第二个错误输出。没有更多的错误!谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-02
    • 2017-07-22
    • 2017-03-24
    • 2016-10-21
    • 1970-01-01
    相关资源
    最近更新 更多