Here my code. I am passing two values into CGRectMake(..)
and getting and error.
let width = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).width
// return Int32 value
let height = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).height
// return Int32 value
myLayer?.frame = CGRectMake(0, 0, width, height)
// returns error: '`Int32`' not convertible to `CGFloat`
How can I convert Int32
to CGFloat
to not return an error?
To convert between numerical data types create a new instance of the target type, passing the source value as parameter. So to convert an
Int32
to aCGFloat
:In your case you can either do:
or:
Note that there is no implicit or explicit type casting between numeric types in swift, so you have to use the same pattern also for converting a
Int
toInt32
or toUInt
etc.