ios8.1 - how to convert Int32 value to CGFloat in swift? -


here code,

let width = cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).width -- return int32

let height = cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).height -- return int32

mylayer?.frame = cgrectmake(0, 0, width, height)

error 'int32' not convertible cgfloat, how can convert int32 cgfloat?

to convert between numerical data types create new instance of target type, passing source value parameter. convert int32 cgfloat:

let int: int32 = 10 let cgfloat = cgfloat(int) 

in case can either do:

let width = cgfloat(cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).width) let height = cgfloat(cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).height)  mylayer?.frame = cgrectmake(0, 0, width, height) 

or:

let width = cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).width let height = cmvideoformatdescriptiongetdimensions(device.activeformat.formatdescription cmvideoformatdescriptionref!).height  mylayer?.frame = cgrectmake(0, 0, cgfloat(width), cgfloat(height)) 

note there no implicit or explicit type casting between numeric types in swift, have use same pattern converting int int32 or uint etc.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -