“'CGFloat' is not convertible to 'Double'” error in Swift (iOS)

前端 未结 1 1994
自闭症患者
自闭症患者 2021-01-21 14:39

I\'m trying to cut an image into 9 pieces in Swift. I\'m getting this error:

\'CGFloat\' is not convertible to \'Double\'

相关标签:
1条回答
  • 2021-01-21 15:10

    In swift there is no implicit conversion of numeric data types, and you are mixing integers and floats. You have to explicitly convert the indexes to CGFloats:

    var intWidth = ( CGFloat(i) * (sizeOfImage.width/3.0))
    var fltHeight = ( CGFloat(j) * (sizeOfImage.height/3.0))
    

    As often happening in swift, the error message is misleading - it says:

    'CGFloat' is not convertible to 'Double'

    whereas I'd expect:

    'CGFloat' is not convertible to 'Int'

    0 讨论(0)
提交回复
热议问题