簡體   English   中英

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...行上收到錯誤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()期望的。


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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM