CGFloat is CoreGraphicsFloat. Itâs for the Core Graphics system, and itâs adopted by UIKit as the unit of measure for all user interface measurement. I think that alone makes it the correct unit for UI calculations on iOS.
When it comes to photos, yes, that makes things a little more interesting. That is often because youâre using photos with the core graphics system. So in this case, itâs actually in a sense unrelated to the UI discussion. Itâs actually the original core reason CGFloat exists, ironically, not the adopted one. Iâd try to pick one or the other for the component youâre working with. If youâre dealing with CoreGraphics, use CGFloat outright. If your math module is separate, work out what works for you and bridge at the right spots? That may also help to deal with Accellerate for faster calculations or something.
That said, you did also mention in your OP ânearly dozens of timesâ. Considering youâre working on a photo-based app, Iâm surprised itâs that small!
Keep in mind the equivalency issue Swift is trying to solve for you by not letting this silently get through. You may be treating them as equivalent, but you never know whatâs coming, and by keeping these separate, or making you cast 20 times, it makes it a lot easier for you to track down regressions if/when you want to port to a new architecture.
Also, even if this may always be a good assumption for you, if Swift allows it silent for everyone who compiles only 64 bit, what happens when they switch to watchOS for a bit of code and it all of a sudden starts breaking? Is that more or less confusing than just saying âtheyâre not necessarily equivalentâ and making you say âIâm aware of thatâ with a cast?
I definitely see the frustration of declaring variables with the type at the call site eg:
let value1: CGFloat = 5
let value2: CGFloat = 7
let value3: CGFloat = 9
let value4: CGFloat = 11
I know itâs not a great solution, but you could always declare upfront under the same type:
let value1, value2, value3, value4: CGFloat
value1 = 5
value2 = 7
value3 = 9
value4 = 11