Reputation: 7534
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
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
Reputation: 52530
Swift doesn't allow mathematical operations with values of different types.
Upvotes: 0