Andre M
Andre M

Reputation: 7534

Swift2: mathematical operations with Int64 and Int32?

What is the right way to deal with an operation that involves both a Int64 and an Int32 in Swift? For example, the following fails with "Binary operator '/' cannot be applied to operands of type 'Int32' and 'Int64'":

let i64 : Int64 = 1
let i32 : Int32 = 1
let val = i32 / i64

The simple scenario here works:

let i64 : Int64 = 1
let i32 : Int32 = 1
let val = Int64(i32) / i64

Now my 'real world' case is, which fails with "Cannot invoke initializer for type 'Int64' with an argument list of type '(Int32)'":

let timedMetadataGroup : AVMutableTimedMetadataGroup
// timedMetadataGroup is initialised with values from another function
let startSecs = timedMetadataGroup.timeRange.start.value.value / Int64(timedMetadataGroup.timeRange.start.timescale.value)

What is different between the pure case and the the above case? How would I resolve this? Is there more than one type of Int32 or Int64?

Upvotes: 1

Views: 69

Answers (2)

Luca Angeletti
Luca Angeletti

Reputation: 59496

You are accessing

timedMetadataGroup.timeRange.start.timescale.value

but the type of timescale is CMTimeScale which is an alias for Int32. So I think you should just stop to timescale and remove the .value part.

let startSecs = timedMetadataGroup.timeRange.start.value / Int64(timedMetadataGroup.timeRange.start.timescale)

Upvotes: 1

gnasher729
gnasher729

Reputation: 52530

Swift doesn't allow mathematical operations with values of different types.

Upvotes: 0

Related Questions