Swift 5.5 auto conversions between CGFloat and Double
Now, Swift converts CGFloat to double and double to CGFloat implicitly for us.
Swift 5.5 came up with a lot of cool additions like actors, Task, aync/await etc. Along with that, a small and super useful addition also came in. Yes, Swift 5.5 compiler does the automatic conversions from CGFloat to Double and Vice-versa. This seems a smaller one in mind but super useful in our daily life.
So far(Before Swift 5.5 new addition), We used to get the error when we try to assign the Double value to CGFloat variable or vice versa, we get the compiler error as below.
“Cannot convert value of type ‘CGFloat’ to specified type ‘Double’ ”
We have to face this more often to pass the CGFloat value to Double or other-way around in our development life. Isn’t it?
Swift 5.5, Auto conversion from CGFloat to Double or ViceVersa.
Swift 5.5 brings this small and very useful addition which does this conversion for us automatically, so we don’t need to do the type conversion any more. Below screenshot is from XCode13 where we don’t get the conversion error. Yeah super useful tiny addition.
Thanks for reading this short one!!!.
Few last words:
My other articles such as Actors in Swift, @MainActor, Thread Sanitiser or TSan, Securing the app content from screenshot or recordings and etc. might be useful to you.
Upgrade your medium membership from here to read good amount of article and scale your skills.