0

I'm in the middle of a project using Swift 1.1 and xCode 6.1.1

I receive the following error when trying to make seconds out of a Value and Timescale

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

on the line following line

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

at ,timescale)

Below are a few lines for reference

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

Any suggestions on how to fix? Or answers to why this is happening?

Things I have tried

I have already uninstalled xCode, restarted, and re-installed.

I've already tried to cast timescale as Int32 like so

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

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

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

, but I receive the error on the line var timescale...

as suggested by @martin-r

new reference code

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

Solved

sinsuren
  • 1,745
  • 2
  • 23
  • 26
Mark
  • 148
  • 3
  • 14

1 Answers1

0

The error message is indeed a bit strange, but the solution is probably to remove the unnecessary .value calls:

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

If currentCellSegment.duration is a struct CMTime then its timescale property is a CMTimeScale aka Int32, and that is what CMTimeMakeWithSeconds() expects.


The value property of Int32 returns a Builtin.Int32, and that causes the strange error message. Example:

func abc(x : Int32) {
    println(x)
}
let x = Int32(1)
abc(x)       // OK
abc(x.value) // error: 'Int32' is not convertible to 'Int32'
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • I receive the error - PATH/ViewControllers/Camera/CaptureScreenViewController.swift:41:21: Cannot invoke 'init' with an argument list of type '($T2, @lvalue CMTimeScale)' on the line var seconds... updating post – Mark Mar 31 '15 at 20:06
  • @MarkMasterson: You did not copy the first line correctly, only the *last* `.value` has to be removed. – Martin R Mar 31 '15 at 20:16
  • Yup! Noticed that looking at the second error output. no more error! thanks – Mark Mar 31 '15 at 20:28