Interchangeable use of CGFloat and Double types
About 2 min
Interchangeable use of CGFloat and Double types 관련
HACKING WITH SWIFT
What's new in Swift?
Interchangeable use of CGFloat and Double types | Changes in Swift 5.5
Interchangeable use of CGFloat and Double types
Available from Swift 5.5
SE-0307 (apple/swift-evolution
) introduced a small but important quality of life improvement: Swift is able to implicitly convert between CGFloat
and Double
in most places where it is needed.
In its simplest form, this means we can add a CGFloat
and a Double
together to produce a new Double
, like this:
import Foundation
let first: CGFloat = 42
let second: Double = 19
let result = first + second
print(result)
Swift implements this by inserting an implicit initializer as needed, and it will always prefer Double
if it’s possible. More importantly, none of this is achieved by rewriting existing APIs: technically things like scaleEffect()
in SwiftUI still work with CGFloat
, but Swift quietly bridges this to Double
.
Other Changes in Swift 5.5
Async await | Changes in Swift 5.5
Async await
Async sequences | Changes in Swift 5.5
Async sequences
Effectful read-only properties | Changes in Swift 5.5
Effectful read-only properties
Structured concurrency | Changes in Swift 5.5
Structured concurrency
async let bindings | Changes in Swift 5.5
async let bindings
Continuations for interfacing async tasks with synchronous code | Changes in Swift 5.5
Continuations for interfacing async tasks with synchronous code
Actors | Changes in Swift 5.5
Actors
Global actors | Changes in Swift 5.5
Global actors
Sendable and @Sendable closures | Changes in Swift 5.5
Sendable and @Sendable closures
if for postfix member expressions | Changes in Swift 5.5
if for postfix member expressions
Codable synthesis for enums with associated values | Changes in Swift 5.5
Codable synthesis for enums with associated values
lazy now works in local contexts | Changes in Swift 5.5
lazy now works in local contexts
Extending property wrappers to function and closure parameters | Changes in Swift 5.5
Extending property wrappers to function and closure parameters
Extending static member lookup in generic contexts | Changes in Swift 5.5
Extending static member lookup in generic contexts