Self.Index.Distance to Int?

           let count = weatherArray.count
           let arrayPositionFloat = CGFloat(count) * sliderValue


This is in a protocol extension.

weatherArray is CollectionType.

sliderValue is CGFloat


I need to do multiplikation of Self.Index.Distance (which should be alias for Int) and CGFloat (which is sliderValue) but it does not work.


The compiler complains:

"Binary operator '*' cannot be applied to two CGFloat operands."


It does not make sense. Any help appreciated.

Accepted Answer

CollectionType.Index.Distance defaults to Int, but may not always be Int.

As CollectionType.Index can be any subtype of ForwardIndexType, CollectionType.Index.Distance must be a subtype of _SignedIntegerType.


Which means you can write something like this:

    let count = weatherArray.count.toIntMax()
    let arrayPositionFloat = CGFloat(count) * sliderValue

Thanks a lot!

Self.Index.Distance to Int?
 
 
Q