Even though CGFloat is typealias for Float, you cannot use Float where CGFloat is required

Originator:mail
Number:rdar://17229501 Date Originated:
Status:Open Resolved:
Product:Swift Product Version:
Classification: Reproducible:
 
Summary:
Take the following code:

import CoreGraphics

var f1: Float = 1
var f2: Float = 2

var size = CGSize(width: f1, height: f2)
var point = CGPoint(x: f1, y: f2)

The creation of the CGSize and CGPoint is not allowed because there is no init() that takes two Float values, only an init that takes CGFloat values.

However, CGFloat is a typealias for CFloat, which is a typealias for Float. You'd think that such aliases work both ways but they do not.

Given that type inference is very handy and makes for cleaner code, I'd rather use Swift's native Float values instead of CGFloat.

Steps to Reproduce:
See above

Expected Results:
I can use Float wherever CGFloat is asked for.

Actual Results:
I now need to coerce my Floats into CGFloat values, even though they're the exact same datatype.

Version:
Xcode 6 beta 1 / OS X 10.9.3

Comments

CGFloat defined as float on 32-bit platforms and double on 64-bit platforms. Therefore you should always use CGFloat to get the correct native type for the current platform.

By Florian.Reinhart at June 9, 2014, 10:44 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!