On recent SDK of Darwin platform, Apple has moved the definition of many CG symbols(CGFloat CGSize CGRect) from CoreGraphic to CoreFoundation.
So when we use import CoreFoundation, we can use CGFloat on Darwin now. But it will require use to import the whole Foundation module on non-Darwin platform.
Also, to avoid source breaking change, we may apply some trick which Apple use on Darwin platform to avoid import struct CoreGraphics.CGFloat failing to build issue.
// Currently valid on Darwin platform with macOS 14/iOS 17 SDK
import struct CoreGraphics.CGFloat
import struct CoreFoundation.CGFloat
Background/Context
I have found it first in this discussion [Need Compiler Expert] Is there a way to workaround 'Symbol not found' crash on iOS 15 (sim) for APIS available since iOS 13? - #17 by Kyle-Ye
And besides it I also facing some issue on my other project:
eg.
I used to use the following code before assuming CGXX is defined in CoreGraphics
#if canImport(Darwin)
import CoreGraphics
#else
import Foundation // swift-corelibs-foundation
#endif
Then after the transition of CGXX from CoreGraphics to CoreFoundation
I changed to use the following code
import Foundation
And assume I have a CKit which reexported CoreFoundation.
The following code compiles on Darwin platform but not on Linux nor WASM.
import CKit // or import CoreFoundation
let a: CGFloat = 0.0 // error: cannot find type 'CGFloat' in scope
Considering we will migrate to use swift-foundation later, I'm always try to avoid the direct dependency of Foundation here.
Would it be great if we can align the behavior on all platforms?
GitHub issue link: Move CG symbols to CoreFoundation to match Darwin behavior · Issue #4922 · apple/swift-corelibs-foundation · GitHub